Skip to content

fix(db): preserve operation context and honor ignore_errors on upsert retry#7701

Merged
ar2rsawseen merged 1 commit into
masterfrom
fix/db-retry-ignore-errors
Jun 10, 2026
Merged

fix(db): preserve operation context and honor ignore_errors on upsert retry#7701
ar2rsawseen merged 1 commit into
masterfrom
fix/db-retry-ignore-errors

Conversation

@ar2rsawseen

Copy link
Copy Markdown
Member

What

In the db write wrapper's duplicate-key retry path, the retried attempt re-captured the retry closure's own (empty) arguments via copyArguments. As a result:

  • the error log for a failed retried upsert carried no operation context ({"name":"updateOne","args":[]}), making such entries impossible to attribute to a call site
  • the ignore_errors: [11000] option could never be detected on the retried attempt, so intentionally-racy upserts (e.g. uid allocation on concurrent first requests, which is designed to collide and recover via request restart) were logged as ERROR despite the caller declaring the error expected

Changes

  • capture the original call arguments once per operation and pass them through to the retry closure (also fixes findAndModify remove-result handling on retry, which reads data.args[3])
  • read options from the correct argument position for findAndModify (args[3], not args[2]), so ignore_errors is honored there as well
  • log ignored expected errors at debug level instead of dropping them silently, so a trace remains available for diagnostics

Unexpected duplicate-key errors (callers that do not pass ignore_errors) are still logged as ERROR, now with full operation context on both the first and the retried attempt.

🤖 Generated with Claude Code

… retry

The duplicate-key retry path in the write wrapper re-captured the retry
closure's own (empty) arguments, so the retried attempt logged
{"name":"updateOne","args":[]} with no operation context and the
ignore_errors option could never be detected, surfacing expected
upsert races as ERROR log entries.

- capture the original call arguments once and reuse them for the
  retried attempt (also fixes findAndModify remove result handling
  on retry, which reads data.args[3])
- look up options at the correct argument position for findAndModify
  (args[3], not args[2]) so its ignore_errors is honored too
- log ignored expected errors at debug level instead of dropping
  them silently, keeping a trace for diagnostics

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 10, 2026 14:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes the duplicate-key (11000) upsert retry path in the MongoDB write wrapper so that retried attempts preserve the original operation context (method + args) and correctly honor options.ignore_errors—including for findAndModify, whose options live at args[3].

Changes:

  • Capture original call arguments once per write operation and reuse them across retries to preserve operation context and option detection.
  • Correctly locate findAndModify options at args[3] (vs args[2]) so ignore_errors is respected consistently.
  • Log expected/ignored duplicate-key errors at debug level (instead of suppressing error logs entirely), while still logging unexpected ones as ERROR.

@ar2rsawseen ar2rsawseen merged commit 13838d7 into master Jun 10, 2026
10 of 11 checks passed
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.

3 participants