Skip to content

SERVER-139240 bugfix: Exhaust stream continues after a BSONObjectTooLarge reply failure - #1838

Open
y123456yz wants to merge 1 commit into
mongodb:masterfrom
y123456yz:oversized-exhaust-reply
Open

y123456yz wants to merge 1 commit into
mongodb:masterfrom
y123456yz:oversized-exhaust-reply

Conversation

@y123456yz

Copy link
Copy Markdown
Contributor

In makeCommandResponse() (src/mongo/db/service_entry_point_shard_role.cpp), the exhaust continuation state is computed from the successful reply before the reply is serialized:
if (OpMsg::isFlagSet(message, OpMsg::kExhaustSupported)) {
auto responseObj = replyBuilder->getBodyBuilder().asTempObj();

    if (responseObj.getField("ok").trueValue()) {
        dbResponse.shouldRunAgainForExhaust = replyBuilder->shouldRunAgainForExhaust();
        dbResponse.nextInvocation = replyBuilder->getNextInvocation();
    }
}

try {
    dbResponse.response = replyBuilder->done();
} catch (const ExceptionFor<ErrorCodes::BSONObjectTooLarge>& ex) {
    // ... builds an error reply into a fresh reply builder ...
    dbResponse.response = errorReplyBuilder->done();
}

If replyBuilder->done() throws BSONObjectTooLarge, the successful reply is discarded and replaced by an error reply. However, shouldRunAgainForExhaust and nextInvocation are left set from the discarded successful reply.

As a result, SessionWorkflow treats the error reply as a valid exhaust continuation: it sets the moreToCome flag on the error response and synthesizes another request for the same command. The client therefore receives an error message marked as part of an ongoing exhaust stream, and the server keeps running the command instead of ending the stream.

This is most likely to be hit on an exhaust getMore stream, where a batch can exceed the BSON size limit while the cursor is still alive and setNextInvocation() has already been recorded.

@y123456yz y123456yz changed the title SERVER-139240 bugfix: End the exhaust stream when a reply is replaced… SERVER-139240 bugfix: Exhaust stream continues after a BSONObjectTooLarge reply failure Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant