-
Notifications
You must be signed in to change notification settings - Fork 4.9k
[release/2.1] Fix Sockets hang caused by concurrent Socket disposal (#29786) #29846
Conversation
* Fix Sockets hang caused by concurrent Socket disposal On Windows, if Socket.Send/ReceiveAsync is used, and there's a race condition where the Socket is disposed of between the time that the Socket checks for disposal and attempts to get a NativeOverlapped for use with the operation, the getting of the NativeOverlapped can throw an exception and cause us to leave a field in an inconsistent state, which in turn can cause the operation to hang, waiting for that state to be reset. The fix is to correct the order in which we get the NativeOverlapped vs setting the relevant field. This is a regression in 2.1. * Change ArgumentException to ObjectDisposedException from concurrent disposal If Socket is disposed of concurrently with the first operation on it that allocates a native overlapped, if the disposal happens between the check for disposal and the call to BindHandle, BindHandle may end up throwing an ArgumentException, which is not expected out of SendAsync. We should instead throw an ObjectDisposedException. * Add test for concurrent Send/ReceiveAsync and Dispose on Socket
@davidsh the branch is open and this is approved, could you please do the honors of a CR of this port? |
@davidsh failures are known issues so if you sign off, you can merge this. |
I noticed that no Outerloop tests were run. I know that the newly added tests are Innerloop. But we usually run Outerloop tests especially when networking product code is changed. Since this is a Windows-only change to Sockets, I'll run just the Windows Outerloop. |
@dotnet-bot test Outerloop Windows x64 Debug Build |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Ok to merge after Outerloop CI run.
Outerloop failure is a hang in a System.Runtime test. Stack dumping failed. Unlikely to be related but let's rerun. @dotnet-bot test Outerloop Windows x64 Debug Build please |
The only Sockets failures are in Nano which is expected (those multicast tests were recently disabled on Nano in master branch). @danmosemsft Please confirm the other outerloop failures are expected (I don't think they are related to this PR). If so, this is ok to merge. |
Windows issues are known/irrelevant. |
FYI, we were able to get dumps for the System.Runtime test hang (it is this test: System.Runtime.ExceptionServices.Tests.HandleProcessCorruptedStateExceptionsTests.ProcessExit_Called).
|
Port #29786 to release/2.1
Fixes https://github.com/dotnet/corefx/issues/29785