Repository navigation
🐛 Only call _subscribe once for concurrent subscribes to a channel - #753
Merged
Merged
Conversation
Fixes #739 At the moment, `PubSub.subscribe()` only marks a channel as subscribed once `_subscribe()` calls back, so any other subscribe to that channel in the meantime calls `_subscribe()` again. `sharedb-redis-pubsub` adds a listener per call, so every op is delivered once per listener. This change queues concurrent subscribers behind the in-flight `_subscribe()`. We create all of their streams before calling any callback, since `Agent` can destroy a presence stream from inside its callback, which would otherwise unsubscribe the channel from under the subscribers still waiting. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
There was a problem hiding this comment.
🟢 Approval recommended
The implementation resolves duplicate adapter subscriptions and covers the relevant concurrency edge cases.
0 open findings
What changed in this PR
Queues concurrent channel subscriptions so only one adapter-level _subscribe call occurs.
Changes:
- Tracks in-flight subscriptions per channel.
- Creates all queued streams before invoking callbacks.
- Adds success, failure, teardown, and retry coverage.
| File | Description |
|---|---|
lib/pubsub/index.js |
Coalesces concurrent subscriptions. |
test/pubsub.js |
Tests delivery and stream destruction behavior. |
test/pubsub-memory.js |
Tests errors, retries, and resubscription. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
alecgibson
marked this pull request as ready for review
October 9, 2026 09:46
dawidreedsy
approved these changes
Oct 9, 2026
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 #739
At the moment,
PubSub.subscribe()only marks a channel as subscribed once_subscribe()calls back, so any other subscribe to that channel in the meantime calls_subscribe()again.sharedb-redis-pubsubadds a listener per call, so every op is delivered once per listener.This change queues concurrent subscribers behind the in-flight
_subscribe(). We create all of their streams before calling any callback, sinceAgentcan destroy a presence stream from inside its callback, which would otherwise unsubscribe the channel from under the subscribers still waiting.🤖 Generated with Claude Code
Co-Authored-By: Claude noreply@anthropic.com