Skip to content

fix: hand back the subscription when the sub reply is abandoned or expires - #389

Merged
diegolmello merged 4 commits into
mobilefrom
diegolmello/issue-386-subscription-leak
Aug 24, 2026
Merged

fix: hand back the subscription when the sub reply is abandoned or expires#389
diegolmello merged 4 commits into
mobilefrom
diegolmello/issue-386-subscription-leak

Conversation

@diegolmello

Copy link
Copy Markdown
Member

Proposed changes

sendSubscription recorded the subscription on the AbandonedRequest / ExpiredWait branch but dropped rememberSubscription's return value, so the caller got undefined for a stream the registry genuinely held. With no handle there was no unsub to send, and the orphaned entry was re-established on every reconnect for the rest of the session.

The branch now returns the recorded subscription, establishing the invariant that a handle exists exactly when a registry entry exists. The two adjacent paths already satisfy it: a reply that carries no subs, and a subscribe with no live connection, both write no entry and return nothing.

Closes #386

Steps to reproduce

  • Subscribe to a stream.
  • Have the sub reply be abandoned, or its wait expire, while the connection is still installed.
  • Observe the returned handle is undefined while the subscription registry holds the entry.
  • Attempt teardown: with no handle there is no unsub to send.
  • Reconnect: the orphaned entry is resubscribed.

Tests

  • tears the abandoned entry down through the handle alone
  • is the entry itself when the deadline expires
  • is withheld only where no entry was written
  • updated the pinned assertions for the reopen-abandoned, socket-closed, and deadline-expired paths, which previously pinned the missing handle

A caller is handed a subscription exactly when a registry entry was written.
Supersede ADR-0006, refresh the stale ADR-0004 and ADR-0003 sentences, and
split the handle tests so each path fails by name.
@diegolmello
diegolmello merged commit eef075c into mobile Aug 24, 2026
5 checks passed
@diegolmello
diegolmello deleted the diegolmello/issue-386-subscription-leak branch August 24, 2026 18:25
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.

sendSubscription discards the subscription on the abandoned/expired branch, leaking the stream

1 participant