Skip to content

Handle data track SID reassignment#2000

Merged
ladvoc merged 5 commits into
mainfrom
ladvoc/handle-data-track-sid-change
Jul 14, 2026
Merged

Handle data track SID reassignment#2000
ladvoc merged 5 commits into
mainfrom
ladvoc/handle-data-track-sid-change

Conversation

@ladvoc

@ladvoc ladvoc commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Equivalent to: livekit/rust-sdks#1228

Closes BOT-457

@changeset-bot

changeset-bot Bot commented Jul 9, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 717f2ad

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
livekit-client Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size
dist/livekit-client.esm.mjs 101.48 KB (+0.22% 🔺)
dist/livekit-client.umd.js 110.36 KB (+0.05% 🔺)

@ladvoc
ladvoc marked this pull request as ready for review July 9, 2026 21:01

@devin-ai-integration devin-ai-integration Bot 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.

Devin Review found 2 potential issues.

View 1 additional finding in Devin Review.

Open in Devin Review

Comment thread src/room/data-track/incoming/IncomingDataTrackManager.ts
Comment thread src/room/data-track/incoming/IncomingDataTrackManager.ts
case 'active':
// The SFU does not carry subscriptions across a publisher's full
// reconnect; re-request the subscription under the new SID.
this.emit('sfuUpdateSubscription', { sid: newSid, subscribe: true });

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.

is there a scenario in which the user might have unsubscribed to the data track and we're re-forcing it to subscribe here?

@1egoman 1egoman Jul 10, 2026

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.

One possibility that comes to mind:

  1. A user completes their final subscription for a data track, which calls IncomingDataTrackManager.unSubscribeRequest (see here). but otherwise leaves the descriptor in active type
  2. A SFU full reconnect occurs, and the client must re subscribe via the new SFU to all remote data tracks
  3. Because of the active type on the descriptor, the unsubscribed data track from 1 is resubscribed

@ladvoc Given this, maybe it's worth introducing a unsubscribing or similar descriptor type which can mark that the descriptor is on its way out and should be dropped during a reconnect. Or maybe another way to do this could be to only republish if descriptor.streamControllers.size > 0. Thoughts? I think this would also need to be done on the rust one too, as that also only has the three none / pending / active states.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

unSubscribeRequest doesn't leave the descriptor in the active state:

const previousDescriptorSubscription = descriptor.subscription;
descriptor.subscription = { type: 'none' };
this.subscriptionHandles.delete(previousDescriptorSubscription.subcriptionHandle);

@1egoman 1egoman 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.

Talked about it in a 1:1, generally makes sense

@ladvoc
ladvoc merged commit f2d4f81 into main Jul 14, 2026
9 checks passed
@ladvoc
ladvoc deleted the ladvoc/handle-data-track-sid-change branch July 14, 2026 22:47
@github-actions github-actions Bot mentioned this pull request Jul 14, 2026
lukasIO added a commit that referenced this pull request Jul 21, 2026
main squash-merged the data-channel watermark work (#2013), so its inline
RTCEngine changes conflicted with this branch's refactored data-channel
module. Resolved RTCEngine.ts / RTCEngine.test.ts in favour of the module
version (which already carries all of that work), and took main's other
additions cleanly — notably the data-track SID reassignment fix (#2000)
this branch didn't yet have.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

3 participants