Skip to content

GH-6151 (6.0 backport): The outbox stale sweep releases by key on MySQL and SQL Server - #6165

Merged
jeremydmiller merged 1 commit into
6.0from
gh-6151-outbox-stale-sweep-6.0
Dec 4, 2026
Merged

jeremydmiller merged 1 commit into
6.0from
gh-6151-outbox-stale-sweep-6.0

Conversation

@jeremydmiller

Copy link
Copy Markdown
Member

6.0 backport of #6164 (GH-6151). The commit cherry-picked cleanly onto origin/6.0 (with #6150 merged) with no conflicts or edits. #6164 describes the change: on MySQL and SQL Server, the outbox stale sweep (OutboxStaleTime) reads the stale keys without locking and updates each row by primary key in key order, as a command posted after the recovery batch, so it can no longer deadlock with a sender deleting a row it has just sent.

On 6.x the sweep only runs when OutboxStaleTime is set, or under ServerlessWithOutbox, so fewer apps reach it than on 7.0.

Refs #6151 (closed by #6164 on main).

The repro is weak

Bug_6151_outbox_stale_sweep_deadlocks_with_outgoing_deletes (MySqlTests and SqlServerTests): before the fix, MySQL deadlocked once in 11 runs and SQL Server never in 5 (measured on main). After the fix it is green on both. A regression would most likely still pass it. MySQL's the_sweep_releases_only_the_stale_rows checks the behaviour. SQL Server is in the change because it shares the opt-in with MySQL, not because it reproduced.

What I ran (this branch, net9.0, locally, Docker MySQL 8.0 and SQL Server)

  • dotnet build wolverine.slnx -c Release -f net9.0: 0 errors, 0 warnings.
  • MySqlTests, full suite: 487/487 passed, on a freshly created MySQL container.
  • SqlServerTests, full suite: 817 passed, 1 failed, 2 skipped. The failure was Transport.data_operations.pop_off_buffered (popped 2 of 5 from a SQL Server transport queue), which this change does not touch; its class passed 10/10 twice when re-run on its own. The SQL Server instance is shared with other runs on this machine.

Not run

  • PostgreSQL, SQLite, Oracle, Marten, Polecat and EF Core suites (those providers keep their existing statement in the recovery batch).
  • The full CI / gate suites.
  • No before/after repro runs on this branch; those numbers come from main.

🤖 Generated with Claude Code

BumpStaleOutgoingEnvelopesOperation (OutboxStaleTime, on by default since 7.0) reached the
outbox rows through the owner index, locking each entry before its row, while a sender deletes
a row it has just sent by primary key, locking the row first. On MySQL the two deadlocked, and
a sweep chosen as the victim rolled back the whole shared recovery batch it rode in.

On the providers that release ownership by key (GH-6142), the sweep is now a
ReleaseStaleOutgoingEnvelopesCommand posted after the recovery batch: read the stale keys
without locking, then update by primary key in key order. StaleOutboxSweep.Build is the
single entry point the agent and the tests share.

The deadlock is rare: Bug_6151 (8 connections inserting and deleting outgoing rows, the sweep
every 10 ms) deadlocked once in 11 pre-fix runs on MySQL and never in 5 on SQL Server, so the
test is a weak guard. It passed 8 of 8 after the fix. A second MySQL test checks that the sweep
releases only the stale rows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings December 3, 2026 23:44

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@jeremydmiller
jeremydmiller merged commit 3d97b3d into 6.0 Dec 4, 2026
50 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.

2 participants