Skip to content

fix: detach a subscription's listeners when it ends - #437

Open
brainRottedCoder wants to merge 1 commit into
RocketChat:mobilefrom
brainRottedCoder:fix/detach-subscription-listeners
Open

brainRottedCoder wants to merge 1 commit into
RocketChat:mobilefrom
brainRottedCoder:fix/detach-subscription-listeners

Conversation

@brainRottedCoder

Copy link
Copy Markdown

Summary

Ending a DDP subscription now releases the listeners it registered. The entry carries the callbacks its subscribers passed, a re-established entry inherits that list, and forgetSubscription detaches them. A stopped stream no longer looks live.

Closes #396

Proposed changes

  • ADR-0011: ending the stream ends its callbacks. The record lists them, a re-established record inherits the list, and every path that removes the record detaches them. A function shared by two records on one name stays attached until the last of them goes. A listener registered by another route, onStreamData included, is not the record's and stays.

Changes

  • writeSubscription records every callback on the entry, and a reopen inherits that list instead of registering again.
  • The outbound sub frame is built from id, name and params, so the callback list cannot be serialized onto the wire.
  • forgetSubscription detaches the entry's callbacks. A function still listed by another entry on the same stream name stays attached.
  • onEvent on a handle whose stream has already ended attaches nothing.
  • Specs cover the reopen path and the teardown path separately.

Test plan

  • npm run lint
  • npm run typecheck
  • npx jest — 483 tests, 35 suites
  • CI on this pull request (lint, typecheck, test)

unsubscribe deleted the registry entry and left the callbacks
registered on the stream name, so a stopped stream kept looking
live. The entry now carries those callbacks, a re-established
entry inherits them, and forgetSubscription detaches them.

Closes RocketChat#396

Co-authored-by: Cursor <cursoragent@cursor.com>
@CLAassistant

CLAassistant commented Oct 3, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

unsubscribe leaves the stream's listeners attached (refiling #326)

2 participants