-
Notifications
You must be signed in to change notification settings - Fork 110
fix: add AbortSignal to waitFor() and send trailer on stream abort #636
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
LautaroPetaccio
wants to merge
4
commits into
livekit:main
Choose a base branch
from
LautaroPetaccio:fix/waitfor-abort-signal-and-stream-abort-trailer
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6366308
fix: add AbortSignal to waitFor() and send trailer on stream abort
LautaroPetaccio 150b9a4
chore: add changeset
LautaroPetaccio ecbaef0
chore: merge main
LautaroPetaccio 608f59b
fix: abort disconnectController on server-initiated disconnect
LautaroPetaccio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@livekit/rtc-node': patch | ||
| --- | ||
|
|
||
| Add AbortSignal to waitFor() to clean up listeners on disconnect and send trailer on stream abort |
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
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
devin-ai-integration[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
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
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -96,6 +96,10 @@ export class Room extends (EventEmitter as new () => TypedEmitter<RoomCallbacks> | |||||
|
|
||||||
| private preConnectEvents: FfiEvent[] = []; | ||||||
|
|
||||||
| // Aborted on disconnect to cancel any pending FfiClient.waitFor() listeners, | ||||||
| // preventing them from leaking when the room goes away. | ||||||
| private disconnectController = new AbortController(); | ||||||
|
|
||||||
| private _token?: string; | ||||||
| private _serverUrl?: string; | ||||||
|
|
||||||
|
|
@@ -241,9 +245,13 @@ export class Room extends (EventEmitter as new () => TypedEmitter<RoomCallbacks> | |||||
| this._serverUrl = url; | ||||||
| this.info = cb.message.value.room!.info; | ||||||
| this.connectionState = ConnectionState.CONN_CONNECTED; | ||||||
| // Reset the abort controller for this connection session so that | ||||||
| // a previous disconnect doesn't immediately cancel new operations. | ||||||
| this.disconnectController = new AbortController(); | ||||||
| this.localParticipant = new LocalParticipant( | ||||||
| cb.message.value.localParticipant!, | ||||||
| this.ffiEventLock, | ||||||
| this.disconnectController.signal, | ||||||
| ); | ||||||
|
|
||||||
| for (const pt of cb.message.value.participants) { | ||||||
|
|
@@ -283,6 +291,11 @@ export class Room extends (EventEmitter as new () => TypedEmitter<RoomCallbacks> | |||||
| return ev.message.case == 'disconnect' && ev.message.value.asyncId == res.asyncId; | ||||||
| }); | ||||||
|
|
||||||
| // Abort all pending FfiClient.waitFor() listeners so they don't leak. | ||||||
| // This causes any in-flight operations (publishData, publishTrack, etc.) | ||||||
| // to reject and clean up their event listeners. | ||||||
| this.disconnectController.abort('Room disconnected'); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
as long as there is only one path to trigger this (and the naming is quite obvious) we can just stick to the default abort error being thrown |
||||||
|
|
||||||
| FfiClient.instance.removeListener(FfiClientEvent.FfiEvent, this.onFfiEvent); | ||||||
| this.removeAllListeners(); | ||||||
| } | ||||||
|
|
@@ -599,6 +612,9 @@ export class Room extends (EventEmitter as new () => TypedEmitter<RoomCallbacks> | |||||
| /*} else if (ev.case == 'connected') { | ||||||
| this.emit(RoomEvent.Connected);*/ | ||||||
| } else if (ev.case == 'disconnected') { | ||||||
| // Abort pending waitFor() listeners on server-initiated disconnect too, | ||||||
| // not just on explicit disconnect() calls. | ||||||
| this.disconnectController.abort('Room disconnected'); | ||||||
| this.emit(RoomEvent.Disconnected, ev.value.reason!); | ||||||
| } else if (ev.case == 'reconnecting') { | ||||||
| this.emit(RoomEvent.Reconnecting); | ||||||
|
|
||||||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the expectation would be that
reasonis thrown directly and not further wrapped in an Error