fix(KB-172): fix terminal session leak with activity tracking and stale eviction
- Add session activity tracking (lastActivityAt) to TerminalService - Implement stale session eviction when approaching session limits - Fix WebSocket close handler to properly kill PTY sessions on disconnect - Add lastActivityAt to session listing endpoint for observability - Add comprehensive tests for activity tracking, eviction, and terminal routes - Add changeset for patch release
This commit is contained in:
@@ -317,6 +317,12 @@ export function setupTerminalWebSocket(
|
||||
clearInterval(pingInterval);
|
||||
if (dataUnsub) dataUnsub();
|
||||
if (exitUnsub) exitUnsub();
|
||||
// Kill the PTY session to prevent session leaks
|
||||
try {
|
||||
terminalService.killSession(sessionId);
|
||||
} catch {
|
||||
// Ignore errors during cleanup — session may already be dead
|
||||
}
|
||||
});
|
||||
|
||||
ws.on("error", () => {
|
||||
@@ -324,6 +330,12 @@ export function setupTerminalWebSocket(
|
||||
clearInterval(pingInterval);
|
||||
if (dataUnsub) dataUnsub();
|
||||
if (exitUnsub) exitUnsub();
|
||||
// Kill the PTY session to prevent session leaks
|
||||
try {
|
||||
terminalService.killSession(sessionId);
|
||||
} catch {
|
||||
// Ignore errors during cleanup — session may already be dead
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user