Repository navigation
GH-6151 (6.0 backport): The outbox stale sweep releases by key on MySQL and SQL Server - #6165
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
OutboxStaleTimeis set, or underServerlessWithOutbox, 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 onmain). After the fix it is green on both. A regression would most likely still pass it. MySQL'sthe_sweep_releases_only_the_stale_rowschecks 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.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
main.🤖 Generated with Claude Code