Skip to content

Commit 0d2d8e8

Browse files
authored
Remove RTT check before reading a response from the server. (#1391)
JAVA-5473
1 parent 1f30837 commit 0d2d8e8

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

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

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -349,9 +349,6 @@ public <T> T sendAndReceive(final CommandMessage message, final Decoder<T> decod
349349
CommandEventSender commandEventSender;
350350

351351
try (ByteBufferBsonOutput bsonOutput = new ByteBufferBsonOutput(this)) {
352-
Timeout.onExistsAndExpired(operationContext.getTimeoutContext().timeoutIncludingRoundTrip(), () -> {
353-
throw TimeoutContext.createMongoRoundTripTimeoutException();
354-
});
355352
message.encode(bsonOutput, operationContext);
356353
commandEventSender = createCommandEventSender(message, bsonOutput, operationContext);
357354
commandEventSender.sendStartedEvent();
@@ -432,10 +429,6 @@ private void trySendMessage(final CommandMessage message, final ByteBufferBsonOu
432429

433430
private <T> T receiveCommandMessageResponse(final Decoder<T> decoder, final CommandEventSender commandEventSender,
434431
final OperationContext operationContext) {
435-
Timeout.onExistsAndExpired(operationContext.getTimeoutContext().timeoutIncludingRoundTrip(), () -> {
436-
throw createMongoOperationTimeoutExceptionAndClose(commandEventSender);
437-
});
438-
439432
boolean commandSuccessful = false;
440433
try (ResponseBuffers responseBuffers = receiveResponseBuffers(operationContext)) {
441434
updateSessionContext(operationContext.getSessionContext(), responseBuffers);
@@ -509,6 +502,16 @@ private <T> void sendCommandMessageAsync(final int messageId, final Decoder<T> d
509502
final SingleResultCallback<T> callback, final ByteBufferBsonOutput bsonOutput,
510503
final CommandEventSender commandEventSender, final boolean responseExpected) {
511504
List<ByteBuf> byteBuffers = bsonOutput.getByteBuffers();
505+
506+
boolean[] shouldReturn = {false};
507+
Timeout.onExistsAndExpired(operationContext.getTimeoutContext().timeoutIncludingRoundTrip(), () -> {
508+
callback.onResult(null, createMongoOperationTimeoutExceptionAndClose(commandEventSender));
509+
shouldReturn[0] = true;
510+
});
511+
if (shouldReturn[0]) {
512+
return;
513+
}
514+
512515
sendMessageAsync(byteBuffers, messageId, operationContext, (result, t) -> {
513516
ResourceUtil.release(byteBuffers);
514517
bsonOutput.close();
@@ -519,15 +522,6 @@ private <T> void sendCommandMessageAsync(final int messageId, final Decoder<T> d
519522
commandEventSender.sendSucceededEventForOneWayCommand();
520523
callback.onResult(null, null);
521524
} else {
522-
boolean[] shouldReturn = {false};
523-
Timeout.onExistsAndExpired(operationContext.getTimeoutContext().timeoutIncludingRoundTrip(), () -> {
524-
callback.onResult(null, createMongoOperationTimeoutExceptionAndClose(commandEventSender));
525-
shouldReturn[0] = true;
526-
});
527-
if (shouldReturn[0]) {
528-
return;
529-
}
530-
531525
readAsync(MESSAGE_HEADER_LENGTH, operationContext, new MessageHeaderCallback(operationContext, (responseBuffers, t1) -> {
532526
if (t1 != null) {
533527
commandEventSender.sendFailedEvent(t1);

0 commit comments

Comments
 (0)