You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Fix Sockets hang caused by concurrent Socket disposal (#29786) (#29846)
* 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
handle.DangerousGetHandle(),// to minimize chances of handle recycling from misuse, this should use DangerousAddRef/Release, but it adds too much overhead
handle.DangerousGetHandle(),// to minimize chances of handle recycling from misuse, this should use DangerousAddRef/Release, but it adds too much overhead
@@ -392,8 +392,8 @@ internal unsafe SocketError DoOperationReceiveFromSingleBuffer(SafeCloseSocket h
handle.DangerousGetHandle(),// to minimize chances of handle recycling from misuse, this should use DangerousAddRef/Release, but it adds too much overhead
handle.DangerousGetHandle(),// to minimize chances of handle recycling from misuse, this should use DangerousAddRef/Release, but it adds too much overhead
0 commit comments