-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Never give up in socket transport #7616
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,7 @@ export class SocketTransport { | |
private hasConnectedOnce: boolean = false | ||
|
||
private readonly retryConfig: RetryConfig = { | ||
maxInitialAttempts: 10, | ||
maxInitialAttempts: Infinity, | ||
initialDelay: 1_000, | ||
maxDelay: 15_000, | ||
backoffMultiplier: 2, | ||
|
@@ -67,12 +67,8 @@ export class SocketTransport { | |
await this.connectWithRetry() | ||
} catch (error) { | ||
console.error( | ||
`[SocketTransport] Initial connection attempts failed: ${error instanceof Error ? error.message : String(error)}`, | ||
`[SocketTransport] Unexpected error in connection loop: ${error instanceof Error ? error.message : String(error)}`, | ||
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. This error message might be misleading now. With infinite retries, errors in the connection loop aren't necessarily "unexpected" anymore. Could we update this to be more descriptive, like "Error in connection retry loop" or "Connection retry loop terminated unexpectedly"? |
||
) | ||
|
||
// If we've never connected successfully, we've exhausted our retry attempts | ||
// The user will need to manually retry or fix the issue | ||
this.connectionState = ConnectionState.FAILED | ||
} | ||
} | ||
|
||
|
@@ -83,9 +79,7 @@ export class SocketTransport { | |
try { | ||
this.connectionState = this.retryAttempt === 0 ? ConnectionState.CONNECTING : ConnectionState.RETRYING | ||
|
||
console.log( | ||
`[SocketTransport] Connection attempt ${this.retryAttempt + 1} / ${this.retryConfig.maxInitialAttempts}`, | ||
) | ||
console.log(`[SocketTransport] Connection attempt ${this.retryAttempt + 1}`) | ||
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. With Also, the removed code that threw an error after max attempts provided a clear exit condition. Without it, the only way to exit this loop is through a successful connection or an unexpected error. |
||
|
||
await this.connectSocket() | ||
|
||
|
@@ -111,12 +105,6 @@ export class SocketTransport { | |
this.socket = null | ||
} | ||
|
||
if (this.retryAttempt >= this.retryConfig.maxInitialAttempts) { | ||
this.connectionState = ConnectionState.FAILED | ||
|
||
throw new Error(`Failed to connect after ${this.retryConfig.maxInitialAttempts} attempts`) | ||
} | ||
|
||
console.log(`[SocketTransport] Waiting ${delay}ms before retry...`) | ||
|
||
await this.delay(delay) | ||
|
@@ -204,10 +192,7 @@ export class SocketTransport { | |
this.socket.on("reconnect_failed", () => { | ||
console.error(`[SocketTransport] Socket.IO reconnection failed after all attempts`) | ||
|
||
this.connectionState = ConnectionState.FAILED | ||
|
||
// Socket.IO has exhausted its reconnection attempts | ||
// The connection is now permanently failed until manual intervention | ||
this.connectionState = ConnectionState.RETRYING | ||
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. Is setting the state to |
||
}) | ||
|
||
this.socket.on("error", (error) => { | ||
|
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.
Is setting this to
Infinity
intentional? The while loop inconnectWithRetry()
will never exit naturally now, which could lead to resource exhaustion if the connection continuously fails. Consider:retryConfig
parameter