From e26a2fcedefb69aab21aebf017174af164de8294 Mon Sep 17 00:00:00 2001 From: octo-patch Date: Thu, 23 Apr 2026 12:36:32 +0800 Subject: [PATCH] fix(socket): stop infinite reconnection on Invalid namespace error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the Socket.IO server responds with an 'Invalid namespace' error, the client was falling into the auto-reconnect path and retrying forever. This caused an endless 'Reconnecting...' UI state with no way to recover short of a hard page reload. 'Invalid namespace' is a permanent error — the server explicitly rejected the namespace and retrying will not succeed until the configuration is corrected. Treat it the same as auth failures: disconnect, clear the socket, set authFailed to stop the re-initialization loop, and log a diagnostic message pointing to NEXT_PUBLIC_SOCKET_URL as the likely misconfiguration. Fixes #2704 --- .../sim/app/workspace/providers/socket-provider.tsx | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/apps/sim/app/workspace/providers/socket-provider.tsx b/apps/sim/app/workspace/providers/socket-provider.tsx index 9a63092f97..cf1e8d4836 100644 --- a/apps/sim/app/workspace/providers/socket-provider.tsx +++ b/apps/sim/app/workspace/providers/socket-provider.tsx @@ -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 } else if (socketInstance.active) { // Temporary failure, will auto-reconnect setIsReconnecting(true)