From 8b08c3886cc995076a1021caaf703e8eefe7b7fd Mon Sep 17 00:00:00 2001 From: Alex Blank Date: Sun, 24 May 2026 12:59:28 +0000 Subject: [PATCH] fix: prevent reconnection loop on concurrent connection close - Don't reconnect when server closes old connection with code 4000 - Code 4000 means new connection was established, not an error - Prevents infinite reconnection loop between old/new connections Refs: terminal switching between 4000 error and connected --- apps/web/src/components/terminal.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/apps/web/src/components/terminal.tsx b/apps/web/src/components/terminal.tsx index e49955d..2bf0850 100644 --- a/apps/web/src/components/terminal.tsx +++ b/apps/web/src/components/terminal.tsx @@ -133,7 +133,7 @@ export const TerminalComponent: React.FC = ({ heartbeatCheckRef.current = null; } - if (event.code !== 1000) { + if (event.code !== 1000 && event.code !== 4000) { setError(`Connection closed (code: ${event.code})`); // Attempt reconnection @@ -146,6 +146,10 @@ export const TerminalComponent: React.FC = ({ } }, delay); } + } else if (event.code === 4000) { + // Server closed old connection for concurrent connection - don't reconnect + // The new connection is already established + console.log("Old WebSocket closed by server (new connection established)"); } };