Repository navigation
fix(awareness): stop concurrent dispatchers claiming the same outbox events - #1173
Merged
Merged
Conversation
Contributor
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Follow-up to #1172, which bounded the claim query's work. That PR left one requirement from the brief unmet — concurrency safety — because the gap turned out to predate it.
The bug
Outbox claiming was not mutually exclusive between dispatchers. Four dispatchers claiming in parallel did not merely overlap occasionally: each returned the identical set of events. Racing four workers against a single packet returned
['d0', 'd0', 'd0', 'd0'].Neo4j takes the exclusive node lock at
SetPropertiestime, which is after the eligibilityFilterhas read the row. So every concurrent dispatcher evaluated the predicate against state that was current when it read and stale by the time it wrote, and all of them claimed.This predates #1172 — I reproduced it against that PR's merge-base, where
MATCH ... WHERE ... SEThad the same read-then-lock ordering. It is absorbed today rather than corrupting:finish()matches on{eventId, leaseToken}so a loser's completion is a no-op, and AaaSIngestServiceis idempotent oneventId. The cost is every replica delivering every event, and a lease that means nothing.The fix
Take the lock before reading the state the row is judged on, by writing a property first:
A dispatcher that loses the race now blocks on the lock, re-reads the winner's
deliveringstatus, and filters itself out.Three details worth flagging for review:
claimProbeis written before the predicate, so it must be a property nothing relies on. UsingleaseTokenas the probe would have clobbered the winner's token and broken the fencing infinish().limitrows — for the default batch, 50.pending/failed/delivering, and the only exit from that set is genuine completion, so a concurrent claim of a predecessor keeps it blocking. No lock needed.Verified
SET a.claimProbeline makes them fail again, so the probe is load-bearing rather than incidentally passing on timing.EXPLAINon all four queries — both discovery lanes, the new shortlist, and the lease write — is index-backed with noNodeByLabelScan, so fix(awareness): bound the eVault outbox claim before its predecessor checks #1172's plan shape is intact.Not measured here: the extra round trip and the lock contention under a production-sized backlog. The shortlist adds one indexed read per page, and the probe adds one property write per shortlisted row; both are bounded by batch size rather than backlog size, but the drain rate is worth watching on
/metricsafter deploy alongside the #1172 numbers.