11import { spawn } from "node:child_process" ;
2+ import { resolveTimerTimeoutMs } from "../shared/number-coercion.js" ;
23
34export type LocalCommandProbe = {
45 command : string ;
@@ -20,9 +21,13 @@ export async function probeLocalCommand(
2021 args : string [ ] = [ "--version" ] ,
2122 opts : { outputLimit ?: number ; timeoutKillGraceMs ?: number ; timeoutMs ?: number } = { } ,
2223) : Promise < LocalCommandProbe > {
23- const timeoutMs = opts . timeoutMs ?? 1_500 ;
24+ const timeoutMs = resolveTimerTimeoutMs ( opts . timeoutMs , 1_500 ) ;
2425 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+ ) ;
2631 return await new Promise ( ( resolve ) => {
2732 let stdout = "" ;
2833 let stderr = "" ;
@@ -51,15 +56,12 @@ export async function probeLocalCommand(
5156 const timer = setTimeout ( ( ) => {
5257 timedOut = true ;
5358 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 ) ;
6365 killTimer . unref ?.( ) ;
6466 } , timeoutMs ) ;
6567 child . stdout . setEncoding ( "utf8" ) ;
@@ -99,8 +101,9 @@ export async function probeGatewayUrl(
99101) : Promise < { reachable : boolean ; url : string ; error ?: string } > {
100102 const httpUrl = url . replace ( / ^ w s : / , "http:" ) . replace ( / ^ w s s : / , "https:" ) ;
101103 const healthUrl = new URL ( "/healthz" , httpUrl ) . toString ( ) ;
104+ const timeoutMs = resolveTimerTimeoutMs ( opts . timeoutMs , 900 ) ;
102105 const controller = new AbortController ( ) ;
103- const timeout = setTimeout ( ( ) => controller . abort ( ) , opts . timeoutMs ?? 900 ) ;
106+ const timeout = setTimeout ( ( ) => controller . abort ( ) , timeoutMs ) ;
104107 try {
105108 const response = await fetch ( healthUrl , {
106109 method : "GET" ,
0 commit comments