| 468 | } |
| 469 | |
| 470 | export async function stopSidecar(child: ChildProcess): Promise<void> { |
| 471 | expectedExits.add(child); |
| 472 | const cleanupManifest = () => { |
| 473 | if (!child.pid) return; |
| 474 | const dataDir = sidecarManifestPathByPid.get(child.pid); |
| 475 | if (!dataDir) return; |
| 476 | removeManifestIfOwnedBy(dataDir, child.pid); |
| 477 | sidecarManifestPathByPid.delete(child.pid); |
| 478 | }; |
| 479 | if (child.exitCode !== null || child.killed) { |
| 480 | cleanupManifest(); |
| 481 | return; |
| 482 | } |
| 483 | return new Promise<void>((resolveStop) => { |
| 484 | const timeout = setTimeout(() => { |
| 485 | child.kill("SIGKILL"); |
| 486 | cleanupManifest(); |
| 487 | resolveStop(); |
| 488 | }, 5000); |
| 489 | child.once("exit", () => { |
| 490 | clearTimeout(timeout); |
| 491 | cleanupManifest(); |
| 492 | resolveStop(); |
| 493 | }); |
| 494 | child.kill("SIGTERM"); |
| 495 | }); |
| 496 | } |
| 497 | |
| 498 | export type { DesktopServerSettings }; |