[SERVER-19814] Shell performs getMore with wrong cursor id when "commands" read mode is enabled, for large cursor id values Created: 06/Aug/15  Updated: 19/Sep/15  Resolved: 10/Aug/15

Status: Closed
Project: Core Server
Component/s: Querying, Shell
Affects Version/s: None
Fix Version/s: 3.1.7

Type: Bug Priority: Major - P3
Reporter: J Rassi Assignee: David Storch
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: QuInt 8 08/28/15
Participants:

 Description   

The DBCommandCursor constructor stores the cursor id received from the server as a native Javascript floating-point type, which can't represent large 64-bit integral values with integer-level precision. As a result, the shell will perform a getMore on the wrong cursor id, when the cursor id value it receives from the server is large.

Reproduce as follows:

> db.foo.drop()
false
> db.foo.insert({a:1})
WriteResult({ "nInserted" : 1 })
> db.foo.insert({a:2})
WriteResult({ "nInserted" : 1 })
> db.foo.insert({a:3})
WriteResult({ "nInserted" : 1 })
> db.foo.find().batchSize(2)
{ "_id" : ObjectId("55c3e66795f87f43db9384f2"), "a" : 1 }
{ "_id" : ObjectId("55c3e66a95f87f43db9384f3"), "a" : 2 }
assert: command failed: {
	"ok" : 0,
	"errmsg" : "Cursor not found, cursor id: 4611686066194094000",
	"code" : 43
} : undefined

The following patch helps with reproducibility:

diff --git a/src/mongo/db/catalog/cursor_manager.cpp b/src/mongo/db/catalog/cursor_manager.cpp
index 4adae4e..5aea2a0 100644
--- a/src/mongo/db/catalog/cursor_manager.cpp
+++ b/src/mongo/db/catalog/cursor_manager.cpp
@@ -139,7 +139,7 @@ MONGO_INITIALIZER_WITH_PREREQUISITES(GlobalCursorManager, ("GlobalCursorIdCache"
     return Status::OK();
 }
 
-GlobalCursorIdCache::GlobalCursorIdCache() : _nextId(0), _secureRandom() {}
+GlobalCursorIdCache::GlobalCursorIdCache() : _nextId(2147483648), _secureRandom() {}
 
 GlobalCursorIdCache::~GlobalCursorIdCache() {}



 Comments   
Comment by Githook User [ 10/Aug/15 ]

Author:

{u'username': u'dstorch', u'name': u'David Storch', u'email': u'david.storch@10gen.com'}

Message: SERVER-19814 add compare() method to NumberLong, and use it in shell's implementation of find and getMore commands
Branch: master
https://github.com/mongodb/mongo/commit/a067d03eca22d67a1ca036ea61544cd51df1490b

Generated at Thu Feb 08 03:52:09 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.