Skip to content

Commit b0c405b

Browse files
mweinbachclaude
andcommitted
fix(server): drop cached Windows process names when scanning goes idle
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 4300ed6 commit b0c405b

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

‎apps/server/src/preview/PortScanner.test.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,20 @@ effectIt.effect(
872872
]);
873873
yield* scanner.scan();
874874
expect(tasklistCalls).toBe(2);
875+
876+
// An idle scan drops cached names, since Windows may hand the PID to another process.
877+
yield* scanner.unregisterTerminal({
878+
threadId: "scanner-thread",
879+
terminalId: "scanner-terminal",
880+
});
881+
expect(yield* scanner.scan()).toEqual([]);
882+
yield* scanner.registerTerminalProcesses({
883+
threadId: "scanner-thread",
884+
terminalId: "scanner-terminal",
885+
processIds: [1234],
886+
});
887+
yield* scanner.scan();
888+
expect(tasklistCalls).toBe(3);
875889
}).pipe(Effect.provide(layer));
876890
},
877891
);

‎apps/server/src/preview/PortScanner.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,8 @@ export const make = Effect.gen(function* PortDiscoveryMake() {
723723
}
724724
if (hostPlatform === "win32") {
725725
if (terminalByProcessId.size === 0 && configuredUrls.length === 0) {
726+
// Idle scans skip the pruning in withWindowsProcessNames, and Windows may reuse a PID.
727+
yield* Ref.set(windowsProcessNamesRef, new Map());
726728
return { discovered: [], configured: new Map() } satisfies WebProbeSnapshot;
727729
}
728730
const recoverWindowsProbeFailure = recoverProcessProbeFailure("windows-listeners");

0 commit comments

Comments
 (0)