Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public boolean supportsAdditionalTimeout() {

@Override
public boolean supportsConcurrentClose() {
return false;
return true;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.mongodb.internal.connection.tlschannel.util.Util;

import java.io.IOException;
import java.nio.channels.AsynchronousCloseException;
import java.nio.channels.CancelledKeyException;
import java.nio.channels.ClosedChannelException;
import java.nio.channels.InterruptedByTimeoutException;
Expand Down Expand Up @@ -121,7 +122,9 @@ class RegisteredSocket {
public void close() {
doCancelRead(this, null);
doCancelWrite(this, null);
key.cancel();
if (key != null) {
key.cancel();
}
currentRegistrations.getAndDecrement();
/*
* Actual de-registration from the selector will happen asynchronously.
Expand Down Expand Up @@ -263,6 +266,9 @@ boolean doCancelRead(final RegisteredSocket socket, final ReadOperation op) {
try {
// a null op means cancel any operation
if (op != null && socket.readOperation == op || op == null && socket.readOperation != null) {
if (op == null) {
socket.readOperation.onFailure.accept(new AsynchronousCloseException());
}
socket.readOperation = null;
cancelledReads.increment();
currentReads.decrement();
Expand All @@ -280,6 +286,9 @@ boolean doCancelWrite(final RegisteredSocket socket, final WriteOperation op) {
try {
// a null op means cancel any operation
if (op != null && socket.writeOperation == op || op == null && socket.writeOperation != null) {
if (op == null) {
socket.writeOperation.onFailure.accept(new AsynchronousCloseException());
}
socket.writeOperation = null;
cancelledWrites.increment();
currentWrites.decrement();
Expand Down