Skip to content

CDRIVER-5515 fix assert when legacy exhaust cursor receives no documents #1562

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 2 commits into from
Apr 2, 2024

Conversation

kevinAlbs
Copy link
Collaborator

Summary

Fixes a failed assert when an exhaust cursor receives no documents:

src/libbson/src/bson/bson-reader.c:534 bson_reader_new_from_data(): precondition failed: data

Changes verified with a patch build testing all server 3.6 tasks. 3.6 uses legacy exhaust cursors.

Analysis

Regression was introduced in 6f58b9d.

On the prior commit, the call to bson_reader_new_from_data was the following:

   response->reader =
      bson_reader_new_from_data (response->rpc.reply.documents,
                                 (size_t) response->rpc.reply.documents_len);

response->rpc.reply.documents was always non-NULL. When no documents are received, the pointer is assigned the address of the end of the OP_REPLY.

6f58b9d changed to use mcd_rpc_op_reply_get_documents:

   response->reader = bson_reader_new_from_data (
      mcd_rpc_op_reply_get_documents (response->rpc),
      mcd_rpc_op_reply_get_documents_len (response->rpc));

mcd_rpc_op_reply_get_documents returns NULL if there are no documents. This causes the assert failure in bson_reader_new_from_data.

This PR does not change behavior of mcd_rpc_op_reply_get_documents. Returning NULL is documented behavior. Though mcd_rpc_op_reply_get_documents is not in a public header, it is expected to be used by the Serverless Proxy (as part of CDRIVER-4625).

Create an exhaust cursor with empty results. Fails an assertion when using legacy op codes.
Avoids an assertion failure in bson_reader_new_from_data if a legacy
exhaust cursor receives an empty batch of documents.
@kevinAlbs kevinAlbs marked this pull request as ready for review March 25, 2024 15:50
@kevinAlbs kevinAlbs requested a review from adriandole March 25, 2024 15:50
@kevinAlbs kevinAlbs merged commit 0ddbd4d into mongodb:master Apr 2, 2024
kevinAlbs added a commit that referenced this pull request Apr 2, 2024
…nts (#1562)

* add regression test

Create an exhaust cursor with empty results. Fails an assertion when using legacy op codes.

* CDRIVER-5515 handle NULL for OP_REPLY documents

Avoids an assertion failure in bson_reader_new_from_data if a legacy
exhaust cursor receives an empty batch of documents.
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.

2 participants