Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SqlDataReader.ReadAsync blocks same thread to execute synchronous code #24800

Closed
geleems opened this issue Jan 26, 2018 · 1 comment
Closed
Assignees
Milestone

Comments

@geleems
Copy link

geleems commented Jan 26, 2018

Customer reported an issue for SqlDataReader.ReadAsync() method actually runs synchronously, and it blocks the calling thread until data is fed from SQL Server.

Here is the detail description of the issue from the customer:

I want to be able to write asynchronous code in C# which can reliably yield a Task upon anything that, in synchronous code, would block.
All of my setup code and the initialization of the SqlCommand is fairly small and does not have a performance hit if I run it on a UI thread in winforms.
However, because ReadAsync() does not actually always run asynchronously, depending on the query, even though I have await MyFunctionWhichCallsReadAsync();, the effect is that the UI thread is blocked causing a bad experience for the user.
It is misleading that ReadAsync() is named "Async" when it will block the caller.
This prevents a caller which would start multiple asynchronous operation and wait for them concurrently from doing so.
E.g., if I do the following, no concurrency will happen even though it should:

var readTask = reader.ReadAsync();
var backgroundThingTask = DoSomethingElseConcurrentlyAsync();
var readResult = await readTask;
await backgroundThingTask;

This is because reader.ReadAsync() will block without returning a Task until it actually receives data from SQL Server.

Repro code: https://github.com/binki/connect3139210

@geleems geleems self-assigned this Jan 26, 2018
@saurabh500
Copy link
Contributor

Closed with dotnet/corefx#26595

@msftgits msftgits transferred this issue from dotnet/corefx Jan 31, 2020
@msftgits msftgits added this to the 2.1.0 milestone Jan 31, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants