-
Type:
Bug
-
Resolution: Fixed
-
Priority:
Major - P3
-
Affects Version/s: 2.5.0
-
Component/s: None
-
None
-
None
-
Go Drivers
-
Not Needed
-
-
None
-
None
-
None
-
None
-
None
-
None
Detailed steps to reproduce the problem?
InsertMany large number of documents that exceeds maxMessageByte limit (48000000)
x/mongo/driver/batches.go AppendBatchSequence initialises its size accumulator with var size int (zero), ignoring len(dst). By the time it's called, dst already holds the OP_MSG header + command body (insert, $db, lsid, txnNumber, writeConcern, ...). The splitter packs documents up to maxMessageSizeBytes of payload only, so the actual wire message can exceed 48,000,000 bytes. The server closes the connection on read; the driver's write fails with broken pipe.
The bug only fires in an extremely specific and narrow window:
sum(BSON docs) <= 48,000,000 sum(BSON docs) + len(dst-at-splitter-entry) + 15 > 48,000,000
Users hit it only when their payload lands in that strip by accident.
Definition of done
All documents should be divided into batches that do not exceed maxMessageByte limit
Initialise so the budget reflects wire-message size, not payload size.
repro: https://gist.github.com/prestonvasquez/2378fc7da9e0dc568b769361dbed0756
The exact Go version used, with patch level:
go version go1.25.3 linux/amd64
The exact version of the Go driver used:
go.mongodb.org/mongo-driver/v2 v2.5.0
Describe how MongoDB is set up. Local vs Hosted, version, topology, load balanced, etc.
local container
The operating system and version (e.g. Windows 7, OSX 10.8, ...)
Ubuntu 22.04.5 LTS (6.8.0-107-generic)
Security Vulnerabilities
If you’ve identified a security vulnerability in a driver or any other MongoDB project, please report it according to the instructions here