Skip to content

Commit 25d1ee8

Browse files
committed
CSHARP-1704: disposing of sockets in failure scenarios.
1 parent 5498c70 commit 25d1ee8

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

src/MongoDB.Driver.Core/Core/Connections/TcpStreamFactory.cs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -150,16 +150,13 @@ private void Connect(Socket socket, EndPoint endPoint, CancellationToken cancell
150150
{
151151
if (!cancelled && !timedOut)
152152
{
153-
socket.Dispose();
153+
try { socket.Dispose(); } catch { }
154154
throw;
155155
}
156156
}
157157
}
158158

159-
if (socket.Connected)
160-
{
161-
try { socket.Dispose(); } catch { }
162-
}
159+
try { socket.Dispose(); } catch { }
163160

164161
cancellationToken.ThrowIfCancellationRequested();
165162
if (timedOut)
@@ -201,16 +198,13 @@ private async Task ConnectAsync(Socket socket, EndPoint endPoint, CancellationTo
201198
{
202199
if (!cancelled && !timedOut)
203200
{
204-
socket.Dispose();
201+
try { socket.Dispose(); } catch { }
205202
throw;
206203
}
207204
}
208205
}
209206

210-
if (socket.Connected)
211-
{
212-
try { socket.Dispose(); } catch { }
213-
}
207+
try { socket.Dispose(); } catch { }
214208

215209
cancellationToken.ThrowIfCancellationRequested();
216210
if (timedOut)

0 commit comments

Comments
 (0)