Skip to content

Commit 53f3dfa

Browse files
committed
Fix force-stop daemon to handle lock contention gracefully
When cleanupWorkspaceDaemonFiles fails to acquire the daemon registry lock, forceStopDaemon now catches the error and falls back to directly removing the socket file. This preserves the force-stop contract that cleanup must succeed even under contention, which is critical since force-stop is the fallback path when graceful shutdown fails.
1 parent 23c1723 commit 53f3dfa

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

src/cli/daemon-control.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,20 @@ export async function forceStopDaemon(socketPath: string): Promise<void> {
5151
await new Promise((resolve) => setTimeout(resolve, 500));
5252
}
5353
if (entry) {
54-
cleanupWorkspaceDaemonFiles(entry.workspaceKey, {
55-
pid: entry.pid,
56-
socketPath,
57-
allowLiveOwner: true,
58-
});
54+
try {
55+
cleanupWorkspaceDaemonFiles(entry.workspaceKey, {
56+
pid: entry.pid,
57+
socketPath,
58+
allowLiveOwner: true,
59+
});
60+
} catch {
61+
// Lock contention: fall back to direct socket removal.
62+
try {
63+
unlinkSync(socketPath);
64+
} catch {
65+
// Socket may already be gone.
66+
}
67+
}
5968
} else {
6069
// Registry entry missing; cannot derive workspace key from socket path alone.
6170
// Clean up the socket file directly.

0 commit comments

Comments
 (0)