@@ -349,9 +349,6 @@ public <T> T sendAndReceive(final CommandMessage message, final Decoder<T> decod
349
349
CommandEventSender commandEventSender ;
350
350
351
351
try (ByteBufferBsonOutput bsonOutput = new ByteBufferBsonOutput (this )) {
352
- Timeout .onExistsAndExpired (operationContext .getTimeoutContext ().timeoutIncludingRoundTrip (), () -> {
353
- throw TimeoutContext .createMongoRoundTripTimeoutException ();
354
- });
355
352
message .encode (bsonOutput , operationContext );
356
353
commandEventSender = createCommandEventSender (message , bsonOutput , operationContext );
357
354
commandEventSender .sendStartedEvent ();
@@ -432,10 +429,6 @@ private void trySendMessage(final CommandMessage message, final ByteBufferBsonOu
432
429
433
430
private <T > T receiveCommandMessageResponse (final Decoder <T > decoder , final CommandEventSender commandEventSender ,
434
431
final OperationContext operationContext ) {
435
- Timeout .onExistsAndExpired (operationContext .getTimeoutContext ().timeoutIncludingRoundTrip (), () -> {
436
- throw createMongoOperationTimeoutExceptionAndClose (commandEventSender );
437
- });
438
-
439
432
boolean commandSuccessful = false ;
440
433
try (ResponseBuffers responseBuffers = receiveResponseBuffers (operationContext )) {
441
434
updateSessionContext (operationContext .getSessionContext (), responseBuffers );
@@ -509,6 +502,16 @@ private <T> void sendCommandMessageAsync(final int messageId, final Decoder<T> d
509
502
final SingleResultCallback <T > callback , final ByteBufferBsonOutput bsonOutput ,
510
503
final CommandEventSender commandEventSender , final boolean responseExpected ) {
511
504
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
+
512
515
sendMessageAsync (byteBuffers , messageId , operationContext , (result , t ) -> {
513
516
ResourceUtil .release (byteBuffers );
514
517
bsonOutput .close ();
@@ -519,15 +522,6 @@ private <T> void sendCommandMessageAsync(final int messageId, final Decoder<T> d
519
522
commandEventSender .sendSucceededEventForOneWayCommand ();
520
523
callback .onResult (null , null );
521
524
} 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
-
531
525
readAsync (MESSAGE_HEADER_LENGTH , operationContext , new MessageHeaderCallback (operationContext , (responseBuffers , t1 ) -> {
532
526
if (t1 != null ) {
533
527
commandEventSender .sendFailedEvent (t1 );
0 commit comments