-
Notifications
You must be signed in to change notification settings - Fork 455
CDRIVER-3969 error when creating uncompleted cursor with no server ID #1321
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
Conversation
…_reply_with_opts`
If an error occurs, `found` is false. Assert on the error first to print the error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM besides minor comment
@@ -216,5 +216,28 @@ _mongoc_cursor_cmd_new_from_reply (mongoc_client_t *client, | |||
MONGOC_ERROR_CURSOR_INVALID_CURSOR, | |||
"Couldn't parse cursor document"); | |||
} | |||
|
|||
if (0 != cursor->cursor_id) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logic could be simplified here being that there's no other work being done inside of this if statement. However, if you'd rather leave the if statements separate for readability and comments then that's fine as well.
if (0 != cursor->cursor_id) { | |
if (0 != cursor->cursor_id && 0 == cursor->server_id) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like a reasonable simplification. Removed the nested if
.
…#1321) * fix type of BCON_INT32 value * require serverID for open cursor with `mongoc_cursor_new_from_command_reply_with_opts` * document expectations of server ID option * assert `found` after `mongoc_cursor_error` If an error occurs, `found` is false. Assert on the error first to print the error. * remove unnecessary nested `if`
Patch build: https://spruce.mongodb.com/version/6495b91ed1fe075c5a548f5a
Summary
Return an error if
mongoc_cursor_new_from_command_reply(_with_opts)
is called with a non-zero cursor ID and no server ID.Background & Motivation
mongoc_cursor_new_from_command_reply_with_opts
is expected to be used by drivers wrapping the C driver to create amongoc_cursor_t
from a server reply.The server reply indicates whether a cursor is completed by a non-zero
cursor.id
field. Example withmongosh
:The cursor is iterated by sending a
getMore
with the cursor ID:And the server indicates the cursor is closed with a 0
cursor.id
:An uncompleted cursor can be iterated by sending a "getMore" command or closed with a "killCursors" command. The command is expected to be sent to the same server the cursor was created.
This PR proposes returning an error if
mongoc_cursor_new_from_command_reply(_with_opts)
is called with a non-zero cursor ID and a zero server ID.If creating an uncompleted cursor with a zero server ID, the cursor does not know the server that created the cursor. The cursor cannot guarantee the "getMore" or "killCursors" commands will be sent to the originating server. If the commands are sent to the wrong server, this results in a "cursor not found" error for "getMore" or the originating server resources not being destroyed by "killCursors".