Skip to content

Commit f100207

Browse files
committed
WIP
JAVA-4646
1 parent 8684bed commit f100207

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.mongodb.internal.connection;
1818

1919
import com.mongodb.MongoException;
20+
import com.mongodb.MongoInterruptedException;
2021
import com.mongodb.MongoServerUnavailableException;
2122
import com.mongodb.MongoSocketException;
2223
import com.mongodb.ReadPreference;
@@ -201,6 +202,10 @@ public <T> T execute(final CommandProtocol<T> protocol, final InternalConnection
201202
try {
202203
protocol.sessionContext(new ClusterClockAdvancingSessionContext(sessionContext, clusterClock));
203204
return protocol.execute(connection);
205+
} catch (MongoInterruptedException e) {
206+
// Doing this so that we don't try to grab a lock by calling into sdam machinery in the next catch block, and masking
207+
// this exception as a result
208+
throw e;
204209
} catch (MongoException e) {
205210
sdam.handleExceptionAfterHandshake(SdamIssue.specific(e, sdam.context(connection)));
206211
if (e instanceof MongoWriteConcernWithResponseException) {

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.mongodb.internal.connection;
1818

19+
import com.mongodb.MongoInterruptedException;
1920
import com.mongodb.MongoSocketException;
2021
import com.mongodb.MongoSocketOpenException;
2122
import com.mongodb.MongoSocketReadException;
@@ -136,8 +137,18 @@ public ByteBuf read(final int numBytes, final int additionalTimeout) throws IOEx
136137
}
137138
try {
138139
return read(numBytes);
140+
} catch (IOException e) {
141+
// This logic should move up, and also be on the write path, but it's a start
142+
if (Thread.currentThread().isInterrupted()) {
143+
throw new MongoInterruptedException("Socket read interrupted", e);
144+
} else {
145+
throw e;
146+
}
139147
} finally {
140-
socket.setSoTimeout(curTimeout);
148+
// Adding this check because otherwise setSoTimeout throws, masking the original exception
149+
if (!socket.isClosed()) {
150+
socket.setSoTimeout(curTimeout);
151+
}
141152
}
142153
}
143154

0 commit comments

Comments
 (0)