Fix RTCEngine.negotiate EngineEvent.Closing / EngineEvent.Restarting listeners to not subscribe to a new listener every call - #2084
Open
1egoman wants to merge 3 commits into
Open
Conversation
…listener for each negotiation This avoids the MaxListenersExceededWarning which could happen previously if a bunch of listeners were all added at once.
🦋 Changeset detectedLatest commit: 02163c0 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
commented
Sep 3, 2026
Comment on lines
+312
to
+319
| const abortPendingNegotiations = () => { | ||
| // Iterate a copy: each handler removes itself from the set as its negotiation settles. | ||
| for (const abort of Array.from(this.pendingNegotiationAborts)) { | ||
| abort(); | ||
| } | ||
| }; | ||
| this.on(EngineEvent.Closing, abortPendingNegotiations); | ||
| this.on(EngineEvent.Restarting, abortPendingNegotiations); |
Contributor
Author
There was a problem hiding this comment.
Note to reviewers - an important deviation from the example pull request linked in the description is I opted not to use a Future because the pending list needs to be resettable. There also isn't a super elegant way to remove a listener in the finally block in the same way with this solution - I am calling this.pendingNegotiationAborts.delete to do this.
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.
Previously, every
negotiatecall would add a new listener forEngineEvent.ClosingandEngineEvent.Restarting. If this path was hit at too frequent of a rate, many listeners would get added and aMaxListenersExceededWarningwould get logged.Instead, aim for an approach similar to #1896 - attach the listener in one place, and fan out this one listener entry to all
negotiatecalls dynamically.Fixes the first part (point 1) of #1915. The other two points need some further discussion / thought but this one makes a lot of sense to me and was fairly unambiguous.