Repository navigation
GH-5412 The SQL Server scheduled-message poll never waits on a lock - #5422
Merged
Merged
Conversation
Under ordinary three-node load the durability agent's scheduled poll, or a handler's commit, was chosen as a deadlock victim several times a minute. The system_health deadlock graphs show the poll's select reading the inbox under shared page locks and waiting for the next page, while handlers marking their own rows Handled held intent locks on those pages and waited to convert. - The select takes READPAST and ROWLOCK, so it skips any row or page another transaction holds and leaves it for the next poll. - The promotion always uses the inline statement that matches each selected row by primary key. The uspMarkIncomingOwnership procedure joined a table-valued parameter with no statistics, so it scanned the Scheduled rows and waited on rows the poll never selected. Closes #5412 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013nKJrqsJw3j23Xd46q37ob
Merged
This was referenced Nov 9, 2026
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.
Closes #5412.
Cause
The
system_healthdeadlock graphs from a calm three-node chaos baseline (EF Core with the SQL Server queue) all had the same shape. The scheduled poll'sselect TOP 100 ... where status = 'Scheduled'read the inbox under shared page locks and, holding one, waited for the next page. Meanwhile handlers'update ... set status = 'Handled'statements held intent-exclusive locks on those pages and waited to convert. In a chaos run with faults, SQL Server picked a handler's commit as the victim, and that message was dead-lettered. So this was more than log noise.Change
WITH (READPAST, ROWLOCK). The poll skips any row or page another transaction holds and leaves it for the next poll, so it never waits and can't be part of a cycle.(id, received_at). TheuspMarkIncomingOwnershipprocedure joined a table-valued parameter with no statistics, so SQL Server scanned theScheduledrows and waited on rows the poll had not selected. The inline statement already ran underIdAndDestinationorInboxStaleTime. The procedure is left in the schema, unused by this path.Verification
Bug_5412_scheduled_poll_never_waits_on_a_row_lockholds a lock on one due scheduled row from another transaction. It asserts the poll returns promptly, promotes the other row, and leaves the locked oneScheduled. Onmainthe poll waits until the test cancels it. The fullSqlServerTestssuite passes locally: 739 passed, 2 skipped.Calm baselines with the durability chaos rig, 3 workers for 30 seconds (
CHAOS_STORE=ef CHAOS_TRANSPORT=sqlqueue CHAOS_FAULTS=):mainREADPASTonly🤖 Generated with Claude Code
https://claude.ai/code/session_013nKJrqsJw3j23Xd46q37ob