Skip to content

Commit 778da8c

Browse files
fix: prevent spurious 'session not found' warns on session close (#26)
When closing the only session, the WebSocket \onclose\ reconnect handler races with \ emoveSession()\ cleanup. The reconnect fires, opens a new WS, and sends \�ttach\ for the already-deleted session — producing two spurious warn logs. **Fix:** Set \ms.exited = true\ and clear the reconnect timer *before* closing the WebSocket in \ emoveSession()\, so the \onclose\ handler skips reconnection. --- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent d97ea5f commit 778da8c

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

public/terminal.html

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,12 +1350,16 @@ <h3>
13501350
}
13511351

13521352
async function removeSession(id) {
1353-
try { await fetch('/api/sessions/' + encodeURIComponent(id), { method: 'DELETE' }); } catch {}
1354-
13551353
const ms = managed.get(id);
13561354
if (ms) {
1355+
ms.exited = true;
1356+
if (ms.reconnectTimer) { clearTimeout(ms.reconnectTimer); ms.reconnectTimer = null; }
13571357
if (ms.ws) try { ms.ws.close(); } catch {}
1358-
if (ms.reconnectTimer) clearTimeout(ms.reconnectTimer);
1358+
}
1359+
1360+
try { await fetch('/api/sessions/' + encodeURIComponent(id), { method: 'DELETE' }); } catch {}
1361+
1362+
if (ms) {
13591363
ms.term.dispose();
13601364
ms.container.remove();
13611365
managed.delete(id);
@@ -2169,8 +2173,9 @@ <h3>
21692173
for (const id of [...managed.keys()]) {
21702174
if (!serverIds.has(id)) {
21712175
const ms = managed.get(id);
2176+
ms.exited = true;
2177+
if (ms.reconnectTimer) { clearTimeout(ms.reconnectTimer); ms.reconnectTimer = null; }
21722178
if (ms.ws) try { ms.ws.close(); } catch {}
2173-
if (ms.reconnectTimer) clearTimeout(ms.reconnectTimer);
21742179
ms.term.dispose();
21752180
ms.container.remove();
21762181
managed.delete(id);

0 commit comments

Comments
 (0)