Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions apps/sim/app/workspace/providers/socket-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
Expand All @@ -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)
Copy link
Copy Markdown

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 causes retryConnection to log "Retrying socket connection after auth failure" when the actual issue is a misconfigured NEXT_PUBLIC_SOCKET_URL, and the init useEffect guard to log "Socket initialization skipped - auth failed." Since authFailed is 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)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit e26a2fc. Configure here.

setIsReconnecting(false)
initializedRef.current = false
Comment on lines +424 to +433
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Misleading authFailed state for namespace errors

authFailed is set to true for a namespace error, but the state variable and several surrounding log messages assume auth is the root cause. Line 327 will log "Socket initialization skipped - auth failed, waiting for retry" even when the actual failure was a bad NEXT_PUBLIC_SOCKET_URL. Likewise, the retryConnection callback logs "Retrying socket connection after auth failure" and its comment block says "Call this when user has re-authenticated". This is only a semantic concern — the guard logic works correctly — but it could mislead developers debugging a namespace misconfiguration.

Consider introducing a separate state variable (e.g. permanentError) or at minimum a permanentFailureReason that both auth and namespace errors can set, so that log messages and the public retryConnection surface accurate context.

} else if (socketInstance.active) {
// Temporary failure, will auto-reconnect
setIsReconnecting(true)
Expand Down