fix(bridge-redis): close subscribe-readiness race that could drop a live message#5
Merged
Merged
Conversation
…ive message subscribe() started its XREAD loop at '$' and returned without awaiting the first (blocking) read. '$' only resolves to the stream's last id when that read registers server-side, so a post() (XADD) racing in during the startup window got an id below the resolved '$' and was dropped forever — it never reached the subscriber. Surfaced as an intermittent failure of the "identical backendMsgId + cursor via live push and via catch-up" conformance test under CI load (Node 24). Fix: capture a concrete stream tail id via XINFO STREAM, awaited before subscribe() resolves, and read strictly after it. A concrete id has no gap, so a message added during startup is still delivered. Falls back to '0' when the stream doesn't exist yet (no history to skip). Verified: redis conformance 20/20. Co-Authored-By: Claude Opus 4.8 (1M context) <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.
Fixes the intermittent Redis conformance failure seen on
main(run) — and it was a real bug, not just a slow test.Root cause
bridge-redissubscribe()started itsXREADloop at'$'and returned without awaiting the first (blocking) read (void loop()).'$'only resolves to the stream's last id when that read actually registers server-side. Apost()(XADD) racing in during that startup window gets an id below the resolved'$'and is dropped forever — so the subscriber receives 0 messages (hence the 3svi.waitFortimeout, not a late arrival). Rare; it slipped through under Node 24 CI load.Fix
Capture a concrete stream tail id via
XINFO STREAM, awaited beforesubscribe()resolves, and read strictly after it. A concrete id has no gap —XREADreturns everything after it, including messages added during startup. Falls back to'0'when the stream doesn't exist yet (no history to skip). Only touchespackages/bridge-redis.Verification
redisconformance suite: 20/20 consecutive runs green (was intermittently failing the live-push test).npm test: 26 files passed / 5 skipped, Redis running for real.tsc -bclean.Note
fix:title → this cuts a 0.2.1 patch release on merge, republishing the correctedbridge-redis(with provenance), and returnsmainto green.🤖 Generated with Claude Code