Skip to content

Commit

Permalink
Fix crashes when tracing enabled and Socket disposed during connect (d…
Browse files Browse the repository at this point in the history
…otnet#35964)

Given the right (wrong) sequence of events, if tracing is enabled and a Socket is disposed of during a connect operation, the tracing code might try to access properties on the Socket that throw ObjectDisposedException, and these exceptions may propagate and crash the process.
  • Loading branch information
stephentoub authored May 7, 2020
1 parent 24c599a commit 6478a0d
Showing 1 changed file with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,14 @@ internal void FinishOperationSyncSuccess(int bytesTransferred, SocketFlags flags
{
_acceptSocket = _currentSocket.UpdateAcceptSocket(_acceptSocket!, _currentSocket._rightEndPoint!.Create(remoteSocketAddress));

if (NetEventSource.IsEnabled) NetEventSource.Accepted(_acceptSocket, _acceptSocket.RemoteEndPoint, _acceptSocket.LocalEndPoint);
if (NetEventSource.IsEnabled)
{
try
{
NetEventSource.Accepted(_acceptSocket, _acceptSocket.RemoteEndPoint, _acceptSocket.LocalEndPoint);
}
catch (ObjectDisposedException) { }
}
}
else
{
Expand All @@ -704,7 +711,14 @@ internal void FinishOperationSyncSuccess(int bytesTransferred, SocketFlags flags
socketError = FinishOperationConnect();
if (socketError == SocketError.Success)
{
if (NetEventSource.IsEnabled) NetEventSource.Connected(_currentSocket!, _currentSocket!.LocalEndPoint, _currentSocket.RemoteEndPoint);
if (NetEventSource.IsEnabled)
{
try
{
NetEventSource.Connected(_currentSocket!, _currentSocket!.LocalEndPoint, _currentSocket.RemoteEndPoint);
}
catch (ObjectDisposedException) { }
}

// Mark socket connected.
_currentSocket!.SetToConnected();
Expand Down

0 comments on commit 6478a0d

Please sign in to comment.