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
This commit is contained in:
@@ -133,7 +133,7 @@ export const TerminalComponent: React.FC<TerminalProps> = ({
|
|||||||
heartbeatCheckRef.current = null;
|
heartbeatCheckRef.current = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.code !== 1000) {
|
if (event.code !== 1000 && event.code !== 4000) {
|
||||||
setError(`Connection closed (code: ${event.code})`);
|
setError(`Connection closed (code: ${event.code})`);
|
||||||
|
|
||||||
// Attempt reconnection
|
// Attempt reconnection
|
||||||
@@ -146,6 +146,10 @@ export const TerminalComponent: React.FC<TerminalProps> = ({
|
|||||||
}
|
}
|
||||||
}, delay);
|
}, 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)");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user