fix: current-candle in-place update raced readers — torn OHLCV served to clients#90
Merged
Merged
Conversation
… to clients CandleRing.updateOrCreate mutates the already-published current Candle (high/low/close/volume/tradeCount) in place on every same-bucket trade, but only head/count were volatile (create path only). Readers copyFrom that object with no happens-before edge → torn candles on any market taking >1 trade/min. Guard mutation + reads with a per-ring StampedLock, mirroring GatewayOrderBook (write lock on mutate, optimistic-read + readlock fallback on getRecent/getCurrent). Concurrency regression test included (verified to fail on the unlocked code). Co-Authored-By: Claude Fable 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.
Found in bug-hunt round 1.
CandleRing.updateOrCreatemutated the published current candle in place with no memory barrier while HTTP/persistence readers copied it → torn OHLCV. Per-ring StampedLock mirroring GatewayOrderBook; concurrency test verified to fail on the unlocked code, pass with the fix. 262 gateway tests green.🤖 Generated with Claude Code