fix: remove fire-and-forget reconnect() from initConnection() catch block (OPTI-2437)#515
Open
devin-ai-integration[bot] wants to merge 1 commit into
Open
Conversation
…lock OPTI-2437 When tokenGenerator() throws a FetchError with a non-401 status, the catch block in initConnection() called this.reconnect() fire-and-forget before re-throwing the error. This created a double-retry path: 1. The fire-and-forget reconnect() could spawn an independent loop (especially when connect() is called directly by user code, where isReconnecting is false) 2. The re-thrown error triggers the caller's retry logic in BaseWebRTC.reconnect() Remove the redundant this.reconnect() call from both View.js and Publish.js. The caller (BaseWebRTC.reconnect()) already handles retry with exponential backoff. The stopReconnection=true logic for 401 errors is preserved. Co-Authored-By: craig.johnston <cjohn@dolby.com>
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
|
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.
Summary
Removes fire-and-forget
this.reconnect()calls from thetokenGenerator()catch blocks in bothView.jsandPublish.jsinitConnection()methods.When
tokenGenerator()throws aFetchErrorwith a non-401 status andautoReconnectis enabled, the old code calledthis.reconnect()without awaiting it, then immediately re-threw the error. This created a double-retry path:reconnect()→connect()→initConnection(): The re-thrown error propagates back toBaseWebRTC.reconnect()'s catch block, which schedules a retry viasetTimeoutwith exponential backoff. Meanwhile, the fire-and-forgetthis.reconnect()is usually blocked by theisReconnectingguard — but not always.connect()call:isReconnectingisfalse, so the fire-and-forgetthis.reconnect()passes the guard and starts a full independent reconnect loop. The re-thrown error also reaches the user, who may retry, resulting in two parallel loops.In all cases, the fire-and-forget call also produced an unhandled promise rejection.
The fix relies on
BaseWebRTC.reconnect()to handle all retry logic (it already does, with exponential backoff). ThestopReconnection = truebehavior for 401 errors andautoReconnect=falseis preserved.Jira: OPTI-2437
Review & Testing Checklist for Human
connect()callers is acceptable. Previously, callingconnect()when tokenGenerator threw a retryable FetchError (e.g. 500) would silently start a reconnect loop. Now, the error propagates to the caller without triggering automatic reconnection. This is intentional but is a breaking behavioral change for consumers who relied on this implicit retry-on-first-connect.reconnect()→connect()→initConnection()path still retries correctly. The thrown error should propagate toBaseWebRTC.reconnect()'s catch block (line 145), which resetsisReconnectingand schedules a retry viasetTimeout. Trace this manually or with a debugger.tokenGeneratorthrowing aFetchErrorduring reconnection. The existing reconnect tests mockreconnect()entirely, so this interaction path is untested before and after this change.Notes
View.jsandPublish.js— both are fixed.initConnection()resetsthis.stopReconnection = falseat its start, so for non-401 retryable errors the flag remainsfalse, correctly allowing the outerreconnect()loop to continue.Link to Devin session: https://dolby.devinenterprise.com/sessions/8efd8a57246d4539b83a9534d7b0f60e
Requested by: @craig-johnston