mirror of
https://github.com/outbackdingo/optimclaw.git
synced 2026-08-25 14:53:34 +00:00
fix(web): close SSE connections on page unload to prevent connection starvation
The browser limits concurrent HTTP/1.1 connections per origin to 6. Without cleanup, SSE connections from prior page loads linger after refresh/navigation, eating into the pool. After 2-3 refreshes, all 6 slots are consumed by stale SSE streams and new API fetch calls queue indefinitely — the UI shows "connected" (SSE works) but data never loads. Add a beforeunload handler that closes both eventSource (chat events) and logEventSource (log stream) so the browser can reuse connections immediately on page reload. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
This commit is contained in:
@@ -215,6 +215,14 @@ document.getElementById('token-input').addEventListener('keydown', (e) => {
|
||||
if (e.key === 'Enter') authenticate();
|
||||
});
|
||||
|
||||
// Close SSE connections on page unload to free the browser's connection pool.
|
||||
// Without this, stale SSE connections from prior page loads linger and exhaust
|
||||
// the HTTP/1.1 per-origin connection limit (6), blocking API fetch calls.
|
||||
window.addEventListener('beforeunload', () => {
|
||||
if (eventSource) { eventSource.close(); eventSource = null; }
|
||||
if (logEventSource) { logEventSource.close(); logEventSource = null; }
|
||||
});
|
||||
|
||||
// Note: main event listener registration is at the bottom of this file (search
|
||||
// "Event Listener Registration"). Do NOT add duplicate listeners here.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user