-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Convert ValueTask to a Task before blocking #11855
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
Conversation
|
@AlexanderSher ping |
|
If debug-only exception isn't enough and throwing |
|
I understand that we should never be calling EnsureCompleted() on non-completed tasks but if the case we accidentally do I'd like to make a best effort and keep customers apps working. Even if sync-over-async is suboptimal and might cause other issues in 90% of the cases it will work just fine. What kind of repro are you looking for? That ValueTasks don't allow GetAwaiter().GetResult() on incomplete tasks or that we do sync-over-async somewhere? |
|
Then we need additional check to ensure that we're trying to wait incomplete task synchronously only on threadpool, something like: (SynchronizationContext.Current == null || SynchronizationContext.Current.GetType() == typeof(SynchronizationContext)) && TaskScheduler.Current == TaskScheduler.DefaultI'd prefer to throw exception rather than introduce possible deadlock. |
|
Do you think it's required considering we are using |
|
In a sync code path |
|
This situation would only happen when sync code accidentally runs an async code path. I'm not saying there is no way to deadlock at all but considering we use |
I would say it is an expected scenario when user adds UI interaction as per retry policy. How else can I update UI to provide notification that request has failed and is going to retry? |
|
What are you proposing? Throwing an exception in the case where customers code would've had a high chance of working? There is also no workaround customer can do if we throw an exception, they can always workaround blocking sync-over async and get their code working. |
|
Yes, I think user must be aware that we have a bug in our code that can potentially hang an application. If we throw an exception, user will know where the bug is and apply workaround. If we hang, it would be much harder to figure out why. The workaround is simple: explicitly call failing API method using |
|
Hm, good point, let me try the changes. |
Fixes #10904