Repository navigation
fix: keep attemptConnection on its own engine when disconnect races the join - #2151
Merged
Merged
Conversation
🦋 Changeset detectedLatest commit: a840412 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
Contributor
size-limit report 📦
|
1egoman
approved these changes
Oct 18, 2026
…he join Room.attemptConnection re-read this.engine after awaiting the signal join. A concurrent disconnect() clears this.engine, so the cleanup path threw a TypeError. A newer connect() replaces it, so a stale attempt closed the newer engine. Capture the engine once and only recreate it if it is still the room's engine. Refs #2150 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A connect() attempt that fails after disconnect() and a newer connect() still called handleDisconnect on the shared Room. That moved the newer attempt to Disconnected and emitted RoomEvent.Disconnected. Only the attempt that owns the room's abort controller now touches shared state, and region failover checks the attempt's own abort signal. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
lukasIO
force-pushed
the
claude/livekit-issue-2150-ce107d
branch
from
October 19, 2026 10:13
e0490a3 to
a840412
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
closes #2150
Room.attemptConnectionreadsthis.engineagain after it awaits the signal join. A concurrentroom.disconnect()setsthis.enginetoundefinedduring that await. The cleanup path then callsthis.engine.close()and throws aTypeError. The reporter of #2150 saw these errors when they left a room about 1 s afterconnect().This change captures the engine once, before the first await, and uses that reference for the whole attempt. The cleanup paths close that engine. They call
recreateEngine()only if it is still the room's engine.A newer connection is the failure case. If
connect()runs again afterdisconnect()while the old join is still pending, the room holds a new engine. When the old join fails, its cleanup closesthis.engine, which is the new engine, and so it breaks the new connection. With this change, the stale attempt closes only its own engine, and it does not disconnect the room.Impact
Two tests in
Room.test.tshold the join open, calldisconnect(), and then fail the join. Onmain, the first test getsTypeError: Cannot read properties of undefinedinstead of a cancelledConnectionError. The second test shows that the stale attempt closes the newer engine. Both tests pass with this change. The rate of this race in production is not measured.The orphaned-engine rejoin in #2150 comes from
RTCEngine.join()reopening a closed engine. #2095 fixes that part onmain, and it is not released yet. This PR covers the remainingRoomside of the issue.🤖 Generated with Claude Code