Repository navigation
fix: set sentinel after subscribe to avoid race condition - #41
Merged
cramforce merged 1 commit intoSep 16, 2026
Merged
Conversation
Contributor
|
+1 |
This was referenced Jun 30, 2026
Contributor
|
@cramforce are you available for a review here? still having issues in production because of this |
Contributor
|
Thanks for the mention. Any chance you can add a test? |
Contributor
Contributor
Author
|
sure! |
ken8203
force-pushed
the
fix/race-condition-sentinel-before-subscribe
branch
2 times, most recently
from
September 2, 2026 16:24
6950274 to
e05fa54
Compare
Contributor
Author
|
Hi @cramforce, I've added a test for the race condition. Please take a look! |
cramforce
approved these changes
Sep 6, 2026
Contributor
|
Please re-push with signed git |
Contributor
|
@ken8203 can you sign commits? |
Previously, the sentinel key was set BEFORE subscribing to the request channel. This caused a race condition where: 1. Producer sets sentinel 2. Consumer detects sentinel exists 3. Consumer publishes request to request channel 4. Producer subscribes to request channel (TOO LATE - message lost!) This fix moves the sentinel set to AFTER the subscribe completes: 1. Producer subscribes to request channel 2. Producer sets sentinel 3. Consumer detects sentinel exists 4. Consumer publishes request (SUCCESS - producer receives it) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
ken8203
force-pushed
the
fix/race-condition-sentinel-before-subscribe
branch
from
September 8, 2026 13:27
e05fa54 to
1d49e36
Compare
Contributor
Author
|
Hi, I've signed the commits. Please check again! |
Contributor
|
@cramforce are we good here? |
Contributor
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.
Summary
Fixes a race condition where consumers could miss the producer's request channel subscription.
Problem
Previously, the sentinel key was set before subscribing to the request channel:
sequenceDiagram participant P as Producer participant R as Redis participant C as Consumer P->>R: SET sentinel = "1" Note over P: Haven't subscribed yet... C->>R: GET sentinel R-->>C: "1" (exists) C->>R: SUBSCRIBE chunk:listenerId C->>R: PUBLISH request:streamId Note over R: ❌ No subscriber, message lost! P->>R: SUBSCRIBE request:streamId Note over P: Too late... C--xC: Timeout (1s)Solution
Move sentinel set to after the subscribe completes:
sequenceDiagram participant P as Producer participant R as Redis participant C as Consumer P->>R: SUBSCRIBE request:streamId Note over P: ✅ Subscribe first P->>R: SET sentinel = "1" Note over P: Then set sentinel C->>R: GET sentinel R-->>C: "1" (exists) C->>R: SUBSCRIBE chunk:listenerId C->>R: PUBLISH request:streamId R-->>P: Received listenerId P->>R: PUBLISH chunk:listenerId R-->>C: Received data Note over C: ✅ Stream works!Changes
ctx.publisher.set(sentinel)fromcreateNewResumableStreamwrapper to inside the actual function, afterctx.subscriber.subscribe()completesTesting
All existing tests pass.