Skip to content

fix: wait for media subs acked on the attached transport instead of re-sending them - #440

Merged
diegolmello merged 5 commits into
mobilefrom
fix/media-subs-ready-on-current-connection
Nov 24, 2026
Merged

diegolmello merged 5 commits into
mobilefrom
fix/media-subs-ready-on-current-connection

Conversation

@diegolmello

@diegolmello diegolmello commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Proposed changes

Driver.waitForNotifyUserMediaSubs no longer re-sends the media subscriptions. It resolves true once both media-signal and media-calls have a ready that arrived on the attached Transport, and false on its deadline.

The old wait re-sent a sub under an id that was usually already active. Meteor's ddp-server (monolith) ignores such a sub: no ready, no nosub. So on monolith servers the wait always ran out, and the app ended every call accepted from the native call UI. ddp-streamer answers a duplicate sub, which is why microservices servers worked.

How it works:

  • The Socket records, per DDP subscription, the Transport that carried the sub its ready answered. Only a ready with a subscription id counts, and only while that Transport is still attached.
  • An entry kept from an abandoned sub, or written offline, is not ready. Forgetting an entry, or sending its unsub, clears its readiness.
  • An entry kept from an expired sub becomes ready if its ready lands later on the attached Transport. Without this, a ready slower than the 10s request deadline left the stream not ready for the life of the connection, and every native accept ended after 8s until the next reopen.
  • After a reopen, nothing carries over. The readys from the subscribeAll that follows the resume login make the streams ready again.
  • Socket/Driver/Rocketchat.resubscribeWhenRecorded is replaced by waitForStreamsReady (same arguments, sends nothing). IDriver changes accordingly. The app is the only consumer and calls only waitForNotifyUserMediaSubs.

This also closes two other ways the old re-send went wrong:

  • After a forced reopen, the re-sent sub could reach the server before the DDP login. The app's login does a REST call first. The server refused it with nosub, the SDK deleted the record, and later calls stopped ringing.
  • A re-send in flight when the Transport closed was abandoned, kept its entry, and counted as acknowledged. The wait then reported ready on a dead connection.

ADR-0016 records the decision and marks the bullets of ADR-0006, ADR-0011 and ADR-0012 that described the old wait.

Issue(s)

https://rocketchat.atlassian.net/browse/NATIVE-1925

How to test or reproduce

  • npm test, npm run typecheck, npm run lint.
  • lib/drivers/__tests__/driver.mediaSubs.spec.ts, "resolves true at once, sending no sub, when both media subs were acked on the attached transport", is the regression test for the monolith failure.
  • In the same file, "counts a ready that lands on the attached transport after its sub ran out its deadline" covers the late ready.
  • Mutation checks run locally, each turning a test red:
    • counting an expired sub as ready before its ready lands;
    • ignoring which Transport a ready came from;
    • accepting a stream when only some of its entries are ready.

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • Breaking change for direct callers of resubscribeWhenRecorded, which is renamed and no longer sends

Further comments

A model check of the app's accept gate against this design passes in every scenario. It covers monolith and microservices, an alive socket, a forced reopen, a socket lost while the gate waits, and a ready that lands after its sub expired. Without the "attached Transport" condition, the gate answers on dead subscriptions after a reopen. Without the late-ready handling, the gate ends the call on a live socket.

A ready frame can list several subs; Meteor sends one after a login
re-runs the connection's subs. The socket emitted it under subs[0]
only, so a later sub sent for the first time never resolved, got no
record for the ready listener to mark, and stayed not ready on that
transport after its deadline.

@OtavioStasiak OtavioStasiak left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@diegolmello
diegolmello merged commit 59708d7 into mobile Nov 24, 2026
5 checks passed
@diegolmello
diegolmello deleted the fix/media-subs-ready-on-current-connection branch November 24, 2026 19:34
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.

2 participants