|
1 | 1 | import { spawn } from "node:child_process"; |
| 2 | +import { resolveTimerTimeoutMs } from "../shared/number-coercion.js"; |
2 | 3 | |
3 | 4 | export type LocalCommandProbe = { |
4 | 5 | command: string; |
@@ -20,9 +21,13 @@ export async function probeLocalCommand(
|
20 | 21 | args: string[] = ["--version"], |
21 | 22 | opts: { outputLimit?: number; timeoutKillGraceMs?: number; timeoutMs?: number } = {}, |
22 | 23 | ): Promise<LocalCommandProbe> { |
23 | | -const timeoutMs = opts.timeoutMs ?? 1_500; |
| 24 | +const timeoutMs = resolveTimerTimeoutMs(opts.timeoutMs, 1_500); |
24 | 25 | const outputLimit = opts.outputLimit ?? LOCAL_COMMAND_PROBE_OUTPUT_MAX_CHARS; |
25 | | -const timeoutKillGraceMs = opts.timeoutKillGraceMs ?? LOCAL_COMMAND_PROBE_KILL_GRACE_MS; |
| 26 | +const timeoutKillGraceMs = resolveTimerTimeoutMs( |
| 27 | +opts.timeoutKillGraceMs, |
| 28 | +LOCAL_COMMAND_PROBE_KILL_GRACE_MS, |
| 29 | +0, |
| 30 | +); |
26 | 31 | return await new Promise((resolve) => { |
27 | 32 | let stdout = ""; |
28 | 33 | let stderr = ""; |
@@ -51,15 +56,12 @@ export async function probeLocalCommand(
|
51 | 56 | const timer = setTimeout(() => { |
52 | 57 | timedOut = true; |
53 | 58 | child.kill("SIGTERM"); |
54 | | -killTimer = setTimeout( |
55 | | -() => { |
56 | | -child.kill("SIGKILL"); |
57 | | -child.stdout.destroy(); |
58 | | -child.stderr.destroy(); |
59 | | -finish(timeoutResult()); |
60 | | -}, |
61 | | -Math.max(0, timeoutKillGraceMs), |
62 | | -); |
| 59 | +killTimer = setTimeout(() => { |
| 60 | +child.kill("SIGKILL"); |
| 61 | +child.stdout.destroy(); |
| 62 | +child.stderr.destroy(); |
| 63 | +finish(timeoutResult()); |
| 64 | +}, timeoutKillGraceMs); |
63 | 65 | killTimer.unref?.(); |
64 | 66 | }, timeoutMs); |
65 | 67 | child.stdout.setEncoding("utf8"); |
@@ -99,8 +101,9 @@ export async function probeGatewayUrl(
|
99 | 101 | ): Promise<{ reachable: boolean; url: string; error?: string }> { |
100 | 102 | const httpUrl = url.replace(/^ws:/, "http:").replace(/^wss:/, "https:"); |
101 | 103 | const healthUrl = new URL("/healthz", httpUrl).toString(); |
| 104 | +const timeoutMs = resolveTimerTimeoutMs(opts.timeoutMs, 900); |
102 | 105 | const controller = new AbortController(); |
103 | | -const timeout = setTimeout(() => controller.abort(), opts.timeoutMs ?? 900); |
| 106 | +const timeout = setTimeout(() => controller.abort(), timeoutMs); |
104 | 107 | try { |
105 | 108 | const response = await fetch(healthUrl, { |
106 | 109 | method: "GET", |
|