Skip to content

Commit

Permalink
Fix for #383 - Prevent double calls of ConnectCompleted when timeout …
Browse files Browse the repository at this point in the history
…occurs.
  • Loading branch information
yaakov-h committed Apr 14, 2017
1 parent 18664db commit 1c3757a
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions SteamKit2/SteamKit2/Networking/Steam3/TcpConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,11 @@ private void Release( bool userRequestedDisconnect )
{
lock (netLock)
{
cancellationToken.Dispose();
cancellationToken = null;
if (cancellationToken != null)
{
cancellationToken.Dispose();
cancellationToken = null;
}

if (netWriter != null)
{
Expand All @@ -86,8 +89,11 @@ private void Release( bool userRequestedDisconnect )
netStream = null;
}

socket.Dispose();
socket = null;
if (socket != null)
{
socket.Dispose();
socket = null;
}

netFilter = null;
}
Expand All @@ -100,7 +106,8 @@ private void Release( bool userRequestedDisconnect )
private void ConnectCompleted(bool success)
{
// Always discard result if our request was cancelled
if (cancellationToken.IsCancellationRequested)
// If we have no cancellation token source, we were already Release()'ed
if (cancellationToken?.IsCancellationRequested ?? true)
{
DebugLog.WriteLine("TcpConnection", "Connection request to {0} was cancelled", destination);
if (success) Shutdown();
Expand Down Expand Up @@ -169,7 +176,7 @@ private void TryConnect(object sender)

if ( WaitHandle.WaitAny( new WaitHandle[] { asyncWaitHandle, cancellationToken.Token.WaitHandle }, timeout) != 0 )
{
ConnectCompleted(false);
Socket.CancelConnectAsync( connectEventArgs );
}
}

Expand Down

0 comments on commit 1c3757a

Please sign in to comment.