| 480 | } |
| 481 | |
| 482 | export async function stopSidecar(child: ChildProcess): Promise<void> { |
| 483 | expectedExits.add(child); |
| 484 | const cleanupManifest = () => { |
| 485 | if (!child.pid) return; |
| 486 | const dataDir = sidecarManifestPathByPid.get(child.pid); |
| 487 | if (!dataDir) return; |
| 488 | removeManifestIfOwnedBy(dataDir, child.pid); |
| 489 | sidecarManifestPathByPid.delete(child.pid); |
| 490 | }; |
| 491 | if (child.exitCode !== null || child.killed) { |
| 492 | cleanupManifest(); |
| 493 | return; |
| 494 | } |
| 495 | return new Promise<void>((resolveStop) => { |
| 496 | const timeout = setTimeout(() => { |
| 497 | child.kill("SIGKILL"); |
| 498 | cleanupManifest(); |
| 499 | resolveStop(); |
| 500 | }, 5000); |
| 501 | child.once("exit", () => { |
| 502 | clearTimeout(timeout); |
| 503 | cleanupManifest(); |
| 504 | resolveStop(); |
| 505 | }); |
| 506 | child.kill("SIGTERM"); |
| 507 | }); |
| 508 | } |
| 509 | |
| 510 | export type { DesktopServerSettings }; |