Add entry-cleaning up behavior when stream got dropped - #218
Conversation
lxsaah
left a comment
There was a problem hiding this comment.
Thanks @solus161, I verified the bug on main (38dc500) and confirmed your PR fixes it.
The drop guard is the right approach. The only real caller throws away the returned id (dispatch.rs:158), so an explicit unsubscribe(id) would have nowhere to be called from. And it does fire where it matters, pump_subscription drops the stream on Unsubscribe, cancel and connection teardown.
Keeping the old cleanup in broadcast is also correct. The stream drops rx before the guard runs, so a broadcast can still see Closed while the entry is there. Removing twice is harmless and ids are never reused.
Two things before merge:
-
The doc comment on
subscribeis now wrong. It still says the next matching broadcast prunes the entry. -
dropped_stream_is_pruned(line 237) no longer tests anything. It broadcasts after dropping, but the guard already removed the entry, so theClosedbranch inbroadcastis now untested.
Also worth a code comment: Drop takes a DashMap lock now, so dropping a stream while holding a reference into subs would deadlock. Can't happen today, but it's easy to miss when editing broadcast later.
What's new: - Add `broadcast_prunes_closes_channel_matched_pattern`, testing for `broadcast` could still prune dropped subscription of matched pattern - Add doc, warning about possible thread-reentrance/deadlock of `Drop for SubEntryGuard`
Really appreciate your comment. I just push a fix, docs and test for |
|
@solus161 All three points addressed and I verified the new state locally: 7/7 tests pass, clippy/fmt/doc clean, CI green. Only wording left, no code issues:
LGTM once those are tidied. |
Description
What's new:
SubEntryfor RAII behavior. Also updatestreaminClientManager.subscribe()to take in the guard and the Receiver;Related Issue
Checklist
make check).