Skip to content

Commit 5eef0fc

Browse files
committed
Add close method.
JAVA-5856
1 parent 38294a7 commit 5eef0fc

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

driver-core/src/main/com/mongodb/internal/connection/TlsChannelStreamFactoryFactory.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,13 +254,23 @@ public void openAsync(final OperationContext operationContext, final AsyncComple
254254
}
255255

256256
private void closeAndTimeout(final AsyncCompletionHandler<Void> handler, final SocketChannel socketChannel) {
257-
InterruptedByTimeoutException interruptedByTimeoutException = new InterruptedByTimeoutException();
257+
// We check if this stream was closed before timeout exception.
258+
boolean streamClosed = isClosed();
259+
260+
//TODO refactor ths draft
261+
InterruptedByTimeoutException timeoutException = new InterruptedByTimeoutException();
258262
try {
259263
socketChannel.close();
260264
} catch (Exception e) {
261-
interruptedByTimeoutException.addSuppressed(e);
265+
//TODO should ignore this exception? We seem to do so in other places
266+
timeoutException.addSuppressed(e);
267+
}
268+
269+
if (streamClosed) {
270+
handler.completed(null);
271+
} else {
272+
handler.failed(new MongoSocketOpenException("Exception opening socket", getAddress(), new InterruptedByTimeoutException()));
262273
}
263-
handler.failed(new MongoSocketOpenException("Exception opening socket", getAddress(), new InterruptedByTimeoutException()));
264274
}
265275

266276
private void initializeTslChannel(final AsyncCompletionHandler<Void> handler, final SocketChannel socketChannel) {

0 commit comments

Comments
 (0)