Skip to content

fix: current-candle in-place update raced readers — torn OHLCV served to clients#90

Merged
emrebulutlar merged 1 commit into
mainfrom
fix/candle-inplace-race
Jul 7, 2026
Merged

fix: current-candle in-place update raced readers — torn OHLCV served to clients#90
emrebulutlar merged 1 commit into
mainfrom
fix/candle-inplace-race

Conversation

@emrebulutlar

Copy link
Copy Markdown
Member

Found in bug-hunt round 1. CandleRing.updateOrCreate mutated 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

… 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>
@emrebulutlar
emrebulutlar merged commit 023f5c5 into main Jul 7, 2026
2 checks passed
@emrebulutlar
emrebulutlar deleted the fix/candle-inplace-race branch July 7, 2026 17:55
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.

1 participant