Repository navigation
Fix HttpListener GetContext race with Close on Unix - #136298
Conversation
Fix `BeginGetContext()` and `GetContextAsync()` never completing in the managed `HttpListener` implementation if they race with `Stop()`, `Close()` or `Abort()`. `_state` is only updated after `Cleanup()` has drained the queue of pending operations, so an operation that passed the state check before the queue was drained could be added to it afterwards, and then nothing would ever complete it. Instead, record that the queue has been drained and complete such operations with an `ObjectDisposedException`, the same as operations that were already pending. Also adds a test that calls `BeginGetContext()` from multiple threads while the listener is terminated. Fixes dotnet#136293. Assisted-by: Claude Code <[email protected]>
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
|
Tagging subscribers to this area: @karelz, @dotnet/ncl |
wfurt
left a comment
There was a problem hiding this comment.
LGTM. thanks for the contribution @martincostello
|
Thanks for the fix. Is a For what it's worth, a standalone repro on 10.0.15 (Ubuntu 24.04 container, 4 CPUs, 60 s per mode, 200 ms grace, then a last look 5 s after the run):
The last row is the shape we hit: 5 of 303 single accepts that raced |
Fix
BeginGetContext()andGetContextAsync()never completing in the managedHttpListenerimplementation if they race withStop(),Close()orAbort()._stateis only updated afterCleanup()has drained the queue of pending operations, so an operation that passed the state check before the queue was drained could be added to it afterwards, and then nothing would ever complete it. Instead, record that the queue has been drained and complete such operations with anObjectDisposedException, the same as operations that were already pending.Also adds a test that calls
BeginGetContext()from multiple threads while the listener is terminated.Fixes #136293.