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

Missing ConfigureAwait(false) for ToListAsync and related async terminating operators #32449

Closed
roji opened this issue Nov 29, 2023 · 3 comments · Fixed by #32450
Closed

Missing ConfigureAwait(false) for ToListAsync and related async terminating operators #32449

roji opened this issue Nov 29, 2023 · 3 comments · Fixed by #32450
Assignees
Labels
area-query closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-bug

Comments

@roji
Copy link
Member

roji commented Nov 29, 2023

Our ToListAsync() implementation doesn't do ConfigureAwait(false) like the rest of the EF code. This wasn't flagged by the analyzer, since await foreach specifically currently isn't covered by CA2007 - that's already been fixed (dotnet/roslyn-analyzers#6652) but not yet released.

Flagged by @lkomanetz in #28159 (comment).

@roji roji self-assigned this Nov 29, 2023
roji added a commit to roji/efcore that referenced this issue Nov 29, 2023
@roji roji added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Nov 29, 2023
@lkomanetz
Copy link

@roji
In issue #28159 they talk about ToListAsync deadlocking on a task that is using a blocking .GetAwaiter().GetResult() call. My understanding from that issue was that it was intentional to leave ConfigureAwait(false) off of it because ToListAsync could call into user code and you didn't want to throw the captured context away in case they were doing something with UI elements (or something that requires the captured context).

Did I misunderstand the conversation in that issue? Also I appreciate you getting back to me on it!

@roji
Copy link
Member Author

roji commented Nov 29, 2023

@lkomanetz it's true that in some very specific (and restricted) flows, we made the decision to preserve the user's synchronization context; but ToListAsync() isn't one of them - ConfigureAwait(false) was just unintentionally left out (e.g. there's ConfigureAwait(false) on ToArrayAsync(), but not on ToListAsync()). In any case, the logic called by ToListAsync() internally does already use ConfigureAwait(false), meaning that the synchronization context is lost anyway.

@lkomanetz
Copy link

Thank you for the clarification and for making that change so quickly. I was going to submit a PR through the guidelines but I struggled to think of a way to expose the bug through a unit test, didn't know if it was needed, and felt it might be better to let those who have more intimate knowledge of the codebase implement it.

@roji roji added this to the 9.0.0 milestone Nov 29, 2023
@ajcvickers ajcvickers modified the milestones: 9.0.0, 9.0.0-preview1 Jan 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-query closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants