Uh oh!
There was an error while loading. Please reload this page.
Serialize Dns async-over-sync requests for the same host - #49171
Conversation
ghost
commented
Mar 4, 2021
Tagging subscribers to this area: @dotnet/ncl Issue DetailsFixes #48566
|
Uh oh!
There was an error while loading. Please reload this page.
davidfowl
commented
Mar 5, 2021
@sebastienros I think we should do proxy test run here (httpclient and YARP). |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
geoffkizer
commented
Mar 5, 2021
Could the code here be simplified using a semaphore per hostname? |
stephentoub
commented
Mar 5, 2021
That's basically what this is: "waiting on the semaphore" is done by waiting on the task currently holding the baton. If you mean actually having a SemaphoreSlim, for example, when is it removed from the dictionary to avoid a potential leak? |
geoffkizer
commented
Mar 5, 2021
Yeah, that's what I meant.
Ref count it under the lock. |
stephentoub
commented
Mar 5, 2021
How does that look different from what I have here? At that point, you're retrieving a semaphore instead of a task from the dictionary, and waiting on semaphore.WaitAsync instead of task, but then also needing to call semaphore.Release()? |
geoffkizer
commented
Mar 5, 2021
It's probably not all that different; it mainly avoids using stuff like ContinueWith. For me, at least, I find it much easier to reason about simple awaits than to reason about ContinueWith, especially when you add stuff like TaskContinuationOptions.ExecuteSynchronously. I've gotten burned here in the past, so now my instinct is to try to avoid doing this if I can. But it's not a big deal either way. |
stephentoub
commented
Mar 5, 2021
It doesn't really avoid it :) In order to be able to support the task getting canceled, you need to be able to do work after the task completes rather than as part of the task. That means either ContinueWith or a separate async method in which we await. I chose the former. If you would strongly prefer it, I can switch to await; I chose ContinueWith because the common case is that cancellation doesn't happen, and with ContinueWith, I can specify OnlyOnCanceled and avoid the continuation in the common case. |
geoffkizer
commented
Mar 5, 2021
Yeah, I understand. And this just makes me wish we optimized async methods better, so we wouldn't have to face that dilemma. But we're not going to fix that today :) I'm happy with the code as it is. |
davidfowl
commented
Mar 5, 2021
The only person I accept using ContinueWith is @stephentoub. I've stopped using it myself though 😆 |
Fixes#48566
cc: @geoffkizer, @davidfowl