Skip to content

GODRIVER-3858 message size exceeds limit of 48000000#2360

Open
koenno wants to merge 2 commits intomongodb:release/2.5from
koenno:godriver3858
Open

GODRIVER-3858 message size exceeds limit of 48000000#2360
koenno wants to merge 2 commits intomongodb:release/2.5from
koenno:godriver3858

Conversation

@koenno
Copy link
Copy Markdown

@koenno koenno commented Apr 14, 2026

GODRIVER-3858

Summary

size should not be 0 at very beginning because there are already some bytes written to dst therefore the size should be initialized with dst length

Background & Motivation

InsertMany large number of documents that exceeds maxMessageByte limit (48000000).
A bug in calculation of message byte size.

@koenno koenno requested a review from a team as a code owner April 14, 2026 12:42
@koenno koenno requested a review from qingyang-hu April 14, 2026 12:42
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes incorrect OP_MSG size accounting when appending batched documents, which could allow writes (e.g., large InsertMany) to exceed the server’s maxMessageSizeBytes (48,000,000).

Changes:

  • Initialize the running size counter in AppendBatchSequence / AppendBatchArray using the current dst length (so pre-written bytes are counted toward the limit).
  • Update unit tests to pass a larger totalSize limit to account for the newly-counted overhead.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
x/mongo/driver/batches.go Fixes message-size calculation by counting bytes already written into dst before appending documents.
x/mongo/driver/batches_test.go Adjusts test inputs for totalSize to reflect the updated size accounting behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread x/mongo/driver/batches_test.go Outdated
Comment on lines +39 to +42
totalMsgSize := len(batches.Documents[0]) + len(batches.Documents[1])
var n int
var err error
n, got, err = batches.AppendBatchSequence(got, 2, len(batches.Documents[0]))
n, got, err = batches.AppendBatchSequence(got, 2, totalMsgSize)
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

totalMsgSize is not actually the total message size here (it excludes OP_MSG/section overhead and also includes the size of a document that isn’t expected to be appended). This makes the test’s intent fragile and tied to the current overhead/identifier length. Consider computing the size limit from the expected encoded bytes (e.g., build dst first and use len(dst) +/- 1) and/or rename the variable to reflect that it’s a size limit rather than an actual message size.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Author

@koenno koenno Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have renamed the variable

Comment thread x/mongo/driver/batches_test.go Outdated
Comment on lines +61 to +64
totalMsgSize := len(batches.Documents[0]) + len(batches.Documents[1])
var n int
var err error
n, got, err = batches.AppendBatchArray(got, 2, len(batches.Documents[0]))
n, got, err = batches.AppendBatchArray(got, 2, totalMsgSize)
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above: the totalMsgSize value here isn’t the actual message size limit (it omits BSON array element overhead) and includes bytes for an element that shouldn’t be appended. To keep the test aligned with the totalSize contract, consider deriving the limit from the expected encoded dst length (or renaming the variable to indicate it’s a limit).

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Author

@koenno koenno Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have renamed the variable

@mongodb-drivers-pr-bot
Copy link
Copy Markdown
Contributor

mongodb-drivers-pr-bot Bot commented Apr 14, 2026

🧪 Performance Results

Commit SHA: 806fe4e

There were no significant changes to the performance to report for version 69df3ecae8cb260007130f1a.

For a comprehensive view of all microbenchmark results for this PR's commit, please check out the Evergreen perf task for this patch.

@mongodb-drivers-pr-bot
Copy link
Copy Markdown
Contributor

API Change Report

No changes found!

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