(
env: Record<string, string>,
body: string,
hardTimeoutMs: number,
progressPaths?: string[]
)
| 55 | }); |
| 56 | |
| 57 | function runChild( |
| 58 | env: Record<string, string>, |
| 59 | body: string, |
| 60 | hardTimeoutMs: number, |
| 61 | progressPaths?: string[] |
| 62 | ): Promise<{ code: number | null; signal: NodeJS.Signals | 'TIMEOUT' | null }> { |
| 63 | const src = ` |
| 64 | const { installMainThreadWatchdog } = require(${JSON.stringify(MODULE)}); |
| 65 | installMainThreadWatchdog(${progressPaths ? JSON.stringify({ progressPaths }) : ''}); |
| 66 | ${body} |
| 67 | `; |
| 68 | const child = spawn(process.execPath, ['-e', src], { |
| 69 | env: { ...process.env, ...env }, |
| 70 | stdio: ['ignore', 'ignore', 'ignore'], |
| 71 | }); |
| 72 | return new Promise((resolve) => { |
| 73 | const timer = setTimeout(() => { |
| 74 | child.kill('SIGKILL'); |
| 75 | resolve({ code: null, signal: 'TIMEOUT' }); |
| 76 | }, hardTimeoutMs); |
| 77 | child.on('exit', (code, signal) => { |
| 78 | clearTimeout(timer); |
| 79 | resolve({ code, signal }); |
| 80 | }); |
| 81 | }); |
| 82 | } |
| 83 | |
| 84 | // Assert the watchdog terminated the process. POSIX surfaces the external |
| 85 | // SIGKILL as signal 'SIGKILL'; Windows has no real signals, so the watchdog's |
no test coverage detected