fix(fleet): watch viewer-session leak + workdir test settle-race (#601)
Some checks failed
ci/woodpecker/push/publish Pipeline was canceled
ci/woodpecker/push/ci Pipeline was canceled

Co-authored-by: Jason Woltje <jason@diversecanvas.com>
Co-committed-by: Jason Woltje <jason@diversecanvas.com>
This commit was merged in pull request #601.
This commit is contained in:
2026-06-22 01:43:21 +00:00
committed by jason.woltje
parent 59c755067e
commit 6dbe452a9f
2 changed files with 22 additions and 11 deletions

View File

@@ -1453,15 +1453,19 @@ export function registerFleetAgentCommands(
await runChecked(runner, buildAgentWatchCreateViewerCommand(agent, viewerName, socketName));
const [bin, args] = splitCommand(buildAgentWatchAttachCommand(viewerName, socketName));
const exitCode = await iRunner(bin, args);
// Best-effort cleanup of the viewer session regardless of how the user detached.
// Errors here are intentionally suppressed — the agent session is unaffected.
const killResult = await runner(
...splitCommand(buildAgentWatchKillViewerCommand(viewerName, socketName)),
);
void killResult; // result is intentionally ignored
let exitCode = 0;
try {
const [bin, args] = splitCommand(buildAgentWatchAttachCommand(viewerName, socketName));
exitCode = await iRunner(bin, args);
} finally {
// ALWAYS clean up the viewer session — even if attach threw or the process was
// interrupted — so stale grouped *-watch-* sessions never accumulate. Errors here
// are intentionally suppressed; the agent session is unaffected.
const killResult = await runner(
...splitCommand(buildAgentWatchKillViewerCommand(viewerName, socketName)),
);
void killResult;
}
if (exitCode !== 0) {
process.exitCode = exitCode;