(socketPath: string)
| 87 | * Uses registry ownership metadata to stop the process before unregistering daemon files. |
| 88 | */ |
| 89 | export async function forceStopDaemon(socketPath: string): Promise<void> { |
| 90 | const entry = findDaemonRegistryEntryBySocketPath(socketPath); |
| 91 | if (!entry) { |
| 92 | throw new Error( |
| 93 | `Cannot force-stop daemon at ${socketPath}: daemon registry metadata is missing`, |
| 94 | ); |
| 95 | } |
| 96 | |
| 97 | const lock = acquireDaemonRegistryMutationLock(entry.workspaceKey); |
| 98 | if (!lock) { |
| 99 | throw new Error(`Unable to acquire daemon registry lock for ${entry.workspaceKey}`); |
| 100 | } |
| 101 | |
| 102 | let termSent: boolean; |
| 103 | try { |
| 104 | validateCurrentRegistryEntry(entry, readDaemonRegistryEntry(entry.workspaceKey), socketPath); |
| 105 | termSent = signalDaemonPid(entry.pid, 'SIGTERM'); |
| 106 | } finally { |
| 107 | lock.release(); |
| 108 | } |
| 109 | if (termSent && !(await waitForPidExit(entry.pid, FORCE_STOP_SIGNAL_TIMEOUT_MS))) { |
| 110 | const killSent = signalDaemonPid(entry.pid, 'SIGKILL'); |
| 111 | if (killSent && !(await waitForPidExit(entry.pid, FORCE_STOP_SIGNAL_TIMEOUT_MS))) { |
| 112 | throw new Error(`Daemon PID ${entry.pid} did not exit after SIGKILL`); |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | cleanupWorkspaceDaemonFiles(entry.workspaceKey, { |
| 117 | pid: entry.pid, |
| 118 | socketPath, |
| 119 | instanceId: entry.instanceId, |
| 120 | allowLiveOwner: true, |
| 121 | }); |
| 122 | } |
| 123 | |
| 124 | export interface StartDaemonBackgroundOptions { |
| 125 | socketPath: string; |
no test coverage detected