Skip to content

Commit

Permalink
CSHARP-1704: disposing of sockets in failure scenarios.
Browse files Browse the repository at this point in the history
  • Loading branch information
craiggwilson committed Aug 10, 2016
1 parent 5498c70 commit 25d1ee8
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions src/MongoDB.Driver.Core/Core/Connections/TcpStreamFactory.cs
Expand Up @@ -150,16 +150,13 @@ private void Connect(Socket socket, EndPoint endPoint, CancellationToken cancell
{
if (!cancelled && !timedOut)
{
socket.Dispose();
try { socket.Dispose(); } catch { }
throw;
}
}
}

if (socket.Connected)
{
try { socket.Dispose(); } catch { }
}
try { socket.Dispose(); } catch { }

cancellationToken.ThrowIfCancellationRequested();
if (timedOut)
Expand Down Expand Up @@ -201,16 +198,13 @@ private async Task ConnectAsync(Socket socket, EndPoint endPoint, CancellationTo
{
if (!cancelled && !timedOut)
{
socket.Dispose();
try { socket.Dispose(); } catch { }
throw;
}
}
}

if (socket.Connected)
{
try { socket.Dispose(); } catch { }
}
try { socket.Dispose(); } catch { }

cancellationToken.ThrowIfCancellationRequested();
if (timedOut)
Expand Down

0 comments on commit 25d1ee8

Please sign in to comment.