Skip to content

Catch the negotiate() rejection on a media-sections requirement - #2108

Merged
1egoman merged 1 commit into
livekit:mainfrom
SergeAx:fix/catch-negotiate-on-media-sections-requirement
Sep 18, 2026
Merged

1egoman merged 1 commit into
livekit:mainfrom
SergeAx:fix/catch-negotiate-on-media-sections-requirement

Conversation

@SergeAx

@SergeAx SergeAx commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

RTCEngine has three this.negotiate() call sites. Two of them attach the same handler:

this.negotiate().catch((err) => {
  this.log.error(err);
});

The third — the one wired to client.onMediaSectionsRequirement — does not:

https://github.com/livekit/client-sdk-js/blob/main/src/room/RTCEngine.ts#L756-L759

So when a renegotiation triggered by the server's media-sections requirement fails, the rejection goes nowhere. Instead of a logged error the application gets an unhandled promise rejection, and because negotiate() rejects from a detached promise there is no stack and no context attached to it.

We hit this on React Native (livekit-client 2.20.0). It reaches Sentry as a bare onunhandledrejection — in our case Error: Session error code: ERROR_CONTENT. Session error description: Failed to apply the description for m= section with mid='0': Local fingerprint does not match identity… — grouped as its own issue, disconnected from the NegotiationError that the same failure also produces through the caught paths. That made it look like two unrelated faults during triage.

This does not change behaviour: negotiate() already calls handleDisconnect('negotiation', ReconnectReason.RR_UNKNOWN) before it rejects, so the engine's own recovery runs either way. The patch only routes the error into the logger the other two call sites already use.

Still present on main and in 2.22.3.

Checks

  • npx tsc --noEmit — clean
  • npx vitest run src/room — 593 passed
  • npx prettier --check — clean
  • Changeset included (patch)

RTCEngine has three `this.negotiate()` call sites; two attach
`.catch((err) => this.log.error(err))` and the one wired to
`client.onMediaSectionsRequirement` does not. A renegotiation that
fails there rejects into nothing, so instead of a logged error the
application sees an unhandled promise rejection with no stack — on
React Native it reaches crash reporting as a bare
`onunhandledrejection`, detached from the disconnect it accompanies.

Nothing changes behaviourally: `negotiate()` already calls
`handleDisconnect` before rejecting, so the engine's own recovery runs
either way. This only routes the error to the logger the other two
call sites use.
@changeset-bot

changeset-bot Bot commented Sep 18, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 8ff8dc9

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

@CLAassistant

CLAassistant commented Sep 18, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@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: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@SergeAx

SergeAx commented Sep 18, 2026

Copy link
Copy Markdown
Contributor Author

This patch is written by an agent (Claude Code @ Opus 5.1 xhigh) and verified by me, a human. Claude's vanity trailer in the commit message is omitted per my local settings.

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

Makes sense to me, thanks for the contribution!

@1egoman
1egoman merged commit 9b8caa1 into livekit:main Sep 18, 2026
6 checks passed
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