-
Type: Bug
-
Resolution: Fixed
-
Priority: Critical - P2
-
Affects Version/s: 3.6.0, 3.6.1, 3.6.2
-
Component/s: Query Operations
-
None
-
(copied to CRM)
ISSUE DESCRIPTION
The 3.6 driver added support for implicit sessions as well as a session pool.
This issue tracks several bugs with implicit session management that cause sessions to be leaked on some query operations.
IMPACT
Applications that are exposed to this leak may first notice it by observing SERVER-33158. Messages like the ones below will appear in the server logs:
2018-02-06T13:18:44.855+0000 E - [thread70181] Assertion: 10334:BSONObj size: 19492699 (0x1296F5B) is invalid. Size must be between 0 and 16793600(16MB) First element: 0: { q: { _id: { id: UUID("5447911f-6c78-4238-aeae-c249bec5df73"), uid: BinData(0, F5748B71272004FF160A969FEE42869CBD48FD155B00AFD0EF604F431FFB2F4F) } }, u: { $currentDate: { lastUse: true }, $setOnInsert: { user: { name: "vocab@admin" } } }, upsert: true } src/mongo/bson/bsonobj.cpp 101 2018-02-06T13:18:44.925+0000 I CONTROL [thread70181] Failed to refresh session cache: Location10334: BSONObj size: 19492699 (0x1296F5B) is invalid. Size must be between 0 and 16793600(16MB) First element: 0: { q: { _id: { id: UUID("5447911f-6c78-4238-aeae-c249bec5df73"), uid: BinData(0, F5748B71272004FF160A969FEE42869CBD48FD155B00AFD0EF604F431FFB2F4F) } }, u: { $currentDate: { lastUse: true }, $setOnInsert: { user: { name: "vocab@admin" } } }, upsert: true }
EXAMPLES
A couple of examples which demonstrate the leaks can be found below.
A MongoCursor that is not closed will leaks an implicit session
MongoCursor<Document> iterator = collection.find().iterator(); while (iterator.hasNext()) { // cursor is not closed iterator.next(); }
Code which uses a cursor and properly closes it are not affected by the leak:
try (MongoCursor<Document> iterator = collection.find().iterator()) { while (iterator.hasNext()) { iterator.next(); } } // or collection.find().forEach((Block<Document>) document -> { // do something ... }); // or ArrayList<Document> documents = collection.find().into(new ArrayList<>());
Any use of the first() method (or findOne() in the DBCollection API):
collection.find().first(); // session is not properly released to the pool
The only workaround for this manifestation of the leak is to replace with explicit use of a MongoCursor, as above.
Original Description
We recently upgraded our production replica set from MongoDB 3.4.11 to 3.6.2. The following error occurs every couple minutes and is output in the Mongo log on the primary. We have also found system.sessions is empty using $listSessions on the config db and an authorized user. On the other hand $listLocalSessions returns many in-memory sessions.
2018-02-06T13:18:44.855+0000 E - [thread70181] Assertion: 10334:BSONObj size: 19492699 (0x1296F5B) is invalid. Size must be between 0 and 16793600(16MB) First element: 0: { q: { _id: { id: UUID("5447911f-6c78-4238-aeae-c249bec5df73"), uid: BinData(0, F5748B71272004FF160A969FEE42869CBD48FD155B00AFD0EF604F431FFB2F4F) } }, u: { $currentDate: { lastUse: true }, $setOnInsert: { user: { name: "vocab@admin" } } }, upsert: true } src/mongo/bson/bsonobj.cpp 101 2018-02-06T13:18:44.925+0000 I CONTROL [thread70181] Failed to refresh session cache: Location10334: BSONObj size: 19492699 (0x1296F5B) is invalid. Size must be between 0 and 16793600(16MB) First element: 0: { q: { _id: { id: UUID("5447911f-6c78-4238-aeae-c249bec5df73"), uid: BinData(0, F5748B71272004FF160A969FEE42869CBD48FD155B00AFD0EF604F431FFB2F4F) } }, u: { $currentDate: { lastUse: true }, $setOnInsert: { user: { name: "vocab@admin" } } }, upsert: true }
- is depended on by
-
DRIVERS-453 Decrease likelihood of implicit session leaks
- Closed
- is related to
-
SERVER-33158 Logical Session refresh batches are too large
- Closed