Skip to content

Commit 699fe46

Browse files
committed
Fix fallback workspace key derivation in forceStopDaemon
The fallback path in forceStopDaemon was broken after socket paths moved to tmpdir. The old logic tried to derive workspace key from basename(dirname(socketPath)), which now returns the socket directory name (e.g. xcodebuildmcp-0dcf2d98505d) instead of the actual workspace key (e.g. XcodeBuildMCP-0dcf2d98505d). When findDaemonRegistryEntryBySocketPath returns null, we can no longer reconstruct the workspace key from the socket path alone. Instead, when the registry entry is missing, directly clean up the socket file to ensure force-stop doesn't silently fail.
1 parent 87c486d commit 699fe46

1 file changed

Lines changed: 17 additions & 10 deletions

File tree

src/cli/daemon-control.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import { spawn } from 'node:child_process';
22
import { fileURLToPath } from 'node:url';
3-
import { dirname, resolve, basename } from 'node:path';
4-
import { existsSync } from 'node:fs';
3+
import { dirname, resolve } from 'node:path';
4+
import { existsSync, unlinkSync } from 'node:fs';
55
import { DaemonClient, DaemonVersionMismatchError } from './daemon-client.ts';
66
import {
77
cleanupWorkspaceDaemonFiles,
88
findDaemonRegistryEntryBySocketPath,
9-
readDaemonRegistryEntry,
109
} from '../daemon/daemon-registry.ts';
1110

1211
/**
@@ -41,9 +40,7 @@ export function getDaemonExecutablePath(): string {
4140
* sends SIGTERM, and removes the stale socket.
4241
*/
4342
export async function forceStopDaemon(socketPath: string): Promise<void> {
44-
const matchingEntry = findDaemonRegistryEntryBySocketPath(socketPath);
45-
const workspaceKey = matchingEntry?.workspaceKey ?? basename(dirname(socketPath));
46-
const entry = matchingEntry ?? readDaemonRegistryEntry(workspaceKey);
43+
const entry = findDaemonRegistryEntryBySocketPath(socketPath);
4744
if (entry?.pid) {
4845
try {
4946
process.kill(entry.pid, 'SIGTERM');
@@ -53,10 +50,20 @@ export async function forceStopDaemon(socketPath: string): Promise<void> {
5350
// Brief wait for the process to exit.
5451
await new Promise((resolve) => setTimeout(resolve, 500));
5552
}
56-
cleanupWorkspaceDaemonFiles(
57-
workspaceKey,
58-
entry ? { pid: entry.pid, socketPath } : { socketPath },
59-
);
53+
if (entry) {
54+
cleanupWorkspaceDaemonFiles(entry.workspaceKey, {
55+
pid: entry.pid,
56+
socketPath,
57+
});
58+
} else {
59+
// Registry entry missing; cannot derive workspace key from socket path alone.
60+
// Clean up the socket file directly.
61+
try {
62+
unlinkSync(socketPath);
63+
} catch {
64+
// Socket may already be gone.
65+
}
66+
}
6067
}
6168

6269
export interface StartDaemonBackgroundOptions {

0 commit comments

Comments
 (0)