Skip to content

Connections must not be closed when timeoutMS expires before sending a request #1573

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 10, 2024
Merged
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 @@ -29,6 +29,7 @@
import java.util.Optional;
import java.util.function.LongConsumer;

import static com.mongodb.assertions.Assertions.assertNotNull;
import static com.mongodb.assertions.Assertions.assertNull;
import static com.mongodb.assertions.Assertions.isTrue;
import static com.mongodb.internal.VisibleForTesting.AccessModifier.PRIVATE;
Expand Down Expand Up @@ -198,7 +199,7 @@ public void runMaxTimeMS(final LongConsumer onRemaining) {
runWithFixedTimeout(timeoutSettings.getMaxTimeMS(), onRemaining);
return;
}
timeout.shortenBy(minRoundTripTimeMS, MILLISECONDS)
assertNotNull(timeoutIncludingRoundTrip())
.run(MILLISECONDS,
() -> {},
onRemaining,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -582,17 +582,19 @@ private <T> void sendAndReceiveAsyncInternal(final CommandMessage message, final
private <T> void sendCommandMessageAsync(final int messageId, final Decoder<T> decoder, final OperationContext operationContext,
final SingleResultCallback<T> callback, final ByteBufferBsonOutput bsonOutput,
final CommandEventSender commandEventSender, final boolean responseExpected) {
List<ByteBuf> byteBuffers = bsonOutput.getByteBuffers();

boolean[] shouldReturn = {false};
Timeout.onExistsAndExpired(operationContext.getTimeoutContext().timeoutIncludingRoundTrip(), () -> {
callback.onResult(null, createMongoOperationTimeoutExceptionAndClose(commandEventSender));
bsonOutput.close();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is another bug we had - we were not closing bsonOutput in this situation.

MongoOperationTimeoutException operationTimeoutException = TimeoutContext.createMongoRoundTripTimeoutException();
commandEventSender.sendFailedEvent(operationTimeoutException);
callback.onResult(null, operationTimeoutException);
shouldReturn[0] = true;
});
if (shouldReturn[0]) {
return;
}

List<ByteBuf> byteBuffers = bsonOutput.getByteBuffers();
sendMessageAsync(byteBuffers, messageId, operationContext, (result, t) -> {
ResourceUtil.release(byteBuffers);
bsonOutput.close();
Expand Down Expand Up @@ -638,13 +640,6 @@ private <T> void sendCommandMessageAsync(final int messageId, final Decoder<T> d
});
}

private MongoOperationTimeoutException createMongoOperationTimeoutExceptionAndClose(final CommandEventSender commandEventSender) {
MongoOperationTimeoutException e = TimeoutContext.createMongoRoundTripTimeoutException();
close();
commandEventSender.sendFailedEvent(e);
return e;
}

private <T> T getCommandResult(final Decoder<T> decoder,
final ResponseBuffers responseBuffers,
final int messageId,
Expand Down