-
Notifications
You must be signed in to change notification settings - Fork 3.5k
fix(socket): stop infinite reconnection on Invalid namespace error #4271
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
base: main
Are you sure you want to change the base?
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 |
|---|---|---|
|
|
@@ -409,6 +409,9 @@ export function SocketProvider({ children, user }: SocketProviderProps) { | |
| error.message?.includes('Authentication failed') || | ||
| error.message?.includes('Authentication required') | ||
|
|
||
| // Check if this is a permanent configuration error — retrying won't help | ||
| const isNamespaceError = error.message?.includes('Invalid namespace') | ||
|
|
||
| if (isAuthError) { | ||
| logger.warn( | ||
| 'Authentication failed - stopping reconnection attempts. User may need to refresh/re-login.' | ||
|
|
@@ -418,6 +421,16 @@ export function SocketProvider({ children, user }: SocketProviderProps) { | |
| setAuthFailed(true) | ||
| setIsReconnecting(false) | ||
| initializedRef.current = false | ||
| } else if (isNamespaceError) { | ||
| logger.warn( | ||
| 'Invalid namespace error - stopping reconnection attempts. Check NEXT_PUBLIC_SOCKET_URL configuration.', | ||
| { message: error.message } | ||
| ) | ||
| socketInstance.disconnect() | ||
| setSocket(null) | ||
| setAuthFailed(true) | ||
| setIsReconnecting(false) | ||
| initializedRef.current = false | ||
|
Comment on lines
+424
to
+433
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.
Consider introducing a separate state variable (e.g. |
||
| } else if (socketInstance.active) { | ||
| // Temporary failure, will auto-reconnect | ||
| setIsReconnecting(true) | ||
|
|
||
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.
Namespace error reuses auth-specific flag and recovery path
Low Severity
The namespace error handler sets
authFailed = true, overloading a flag that semantically represents authentication failure. This causesretryConnectionto log "Retrying socket connection after auth failure" when the actual issue is a misconfiguredNEXT_PUBLIC_SOCKET_URL, and the inituseEffectguard to log "Socket initialization skipped - auth failed." SinceauthFailedis exposed in the context's public API, future consumers could incorrectly show a "re-login" prompt for what is actually a permanent configuration error that no amount of re-authentication will fix.Additional Locations (1)
apps/sim/app/workspace/providers/socket-provider.tsx#L785-L795Reviewed by Cursor Bugbot for commit e26a2fc. Configure here.