Repository navigation
🐛 Broadcast a leave before presence re-created with its ID - #772
alecgibson wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
A critical queue-handling bug can acknowledge a valid presence update without publishing it when a newer queued update fails transformation, leaving subscribers without replacement presence.
1 open issue
What changed in this PR
This PR addresses part of #771 by ordering server-side presence broadcasts so a re-created presence waits for an earlier leave with the same ID.
Changes:
- Queue same-ID broadcasts until the preceding leave is handed to pubsub or rejected, releasing waiters without recursion.
- Shallow-copy disconnect leaves to avoid mutating pending presence updates.
- Add regression tests for ordering, failures, disconnects, and long leave queues.
| File | Description |
|---|---|
test/client/presence/doc-presence.js |
Adds helpers and regression cases for queued presence broadcasts. |
lib/agent.js |
Tracks in-flight leaves, orders broadcasts, and copies disconnect leaves. |
docs/middleware/actions.md |
Documents shallow-copy behavior for disconnect and unsubscribe leaves. |
Review effort: Balanced
63ed268 to
5ca6f59
Compare
5ca6f59 to
54089ef
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Outstanding issues retain queued update closures, payloads, and callbacks indefinitely when a publish callback never fires and leave update acknowledgements potentially blocked after the preceding broadcast is retracted.
2 open issues
Review effort: Balanced
54089ef to
94d055e
Compare
There was a problem hiding this comment.
🟡 Changes recommended
A retracted same-ID update can remain blocked behind a held server-generated leave after a second unsubscribe, preventing its submit callback from completing and requiring a cancellation fix with regression coverage.
1 open issue
2 resolved since last review
Review effort: Balanced
94d055e to
9498af0
Compare
9498af0 to
99b160f
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Canceled updates remain in the blocking leave’s waiters array after completion, causing unbounded retention during repeated subscribe/submit/unsubscribe cycles if the leave stalls.
1 open issue
1 resolved since last review
Review effort: Balanced
99b160f to
4209105
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Disconnect cleanup misses queued updates for channels removed by unsubscribe, potentially retaining their payloads and callbacks indefinitely; retraction must cover pending broadcasts and include a regression test.
1 open issue
1 resolved since last review
Review effort: Balanced
4209105 to
31caf05
Compare
Refs #771 At the moment, a presence re-created with the ID of one that's leaving can be transformed and published before the leave: 1. Destroy a presence, and hold its leave's snapshot read in the database 2. Re-create it with the same ID, at the doc's version 3. Release the leave: subscribers drop the re-created presence, since its `pv` restarted, and then clear it with the leave This change has presence wait, once through middleware, until each leave of its ID that arrived before it has been handed to pubsub, superseded or rejected. It checks again after each one, since a later leave can be rejected while an earlier one is still transforming. Presence retracted by an unsubscribe or a disconnect neither waits nor is waited on, since it's either dropped or goes out as a leave, and the client's stored presence gets a leave of its own. Waiters are released once the leave's `publish()` is called, not when it calls back, so pubsub adapters must deliver an instance's messages in call order, as both the [memory][1] and [Redis][2] adapters do. That way an adapter that never calls back can't hold up the ID. [1]: https://github.com/share/sharedb/blob/76c01034f653d68d42b257803f0e0eb6e66aa1b8/lib/pubsub/memory.js#L28-L39 [2]: https://github.com/share/sharedb-redis-pubsub/blob/4909f88651d2d91086857218ea2f94fde107b156/index.js#L79-L85 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
31caf05 to
e739ae7
Compare


Refs #771
At the moment, a presence re-created with the ID of one that's leaving can be transformed and published before the leave:
pvrestarted, and then clear it with the leaveThis change has presence wait, once through middleware, until each leave of its ID that arrived before it has been handed to pubsub, superseded or rejected. It checks again after each one, since a later leave can be rejected while an earlier one is still transforming. Presence retracted by an unsubscribe or a disconnect neither waits nor is waited on, since it's either dropped or goes out as a leave, and the client's stored presence gets a leave of its own.
Waiters are released once the leave's
publish()is called, not when it calls back, so pubsub adapters must deliver an instance's messages in call order, as both the memory and Redis adapters do. That way an adapter that never calls back can't hold up the ID.🤖 Generated with Claude Code
Co-Authored-By: Claude noreply@anthropic.com