fix windows e2e backend not stopping on sigterm waiting 10s for no reason (#21781)
This commit is contained in:
@@ -44,8 +44,12 @@ async function waitForHealth(url: string, probe = "/global/health") {
|
|||||||
throw new Error(`Timed out waiting for backend health at ${url}${probe}${last ? ` (${last})` : ""}`)
|
throw new Error(`Timed out waiting for backend health at ${url}${probe}${last ? ` (${last})` : ""}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function done(proc: ReturnType<typeof spawn>) {
|
||||||
|
return proc.exitCode !== null || proc.signalCode !== null
|
||||||
|
}
|
||||||
|
|
||||||
async function waitExit(proc: ReturnType<typeof spawn>, timeout = 10_000) {
|
async function waitExit(proc: ReturnType<typeof spawn>, timeout = 10_000) {
|
||||||
if (proc.exitCode !== null) return
|
if (done(proc)) return
|
||||||
await Promise.race([
|
await Promise.race([
|
||||||
new Promise<void>((resolve) => proc.once("exit", () => resolve())),
|
new Promise<void>((resolve) => proc.once("exit", () => resolve())),
|
||||||
new Promise<void>((resolve) => setTimeout(resolve, timeout)),
|
new Promise<void>((resolve) => setTimeout(resolve, timeout)),
|
||||||
@@ -123,11 +127,11 @@ export async function startBackend(label: string, input?: { llmUrl?: string }):
|
|||||||
return {
|
return {
|
||||||
url,
|
url,
|
||||||
async stop() {
|
async stop() {
|
||||||
if (proc.exitCode === null) {
|
if (!done(proc)) {
|
||||||
proc.kill("SIGTERM")
|
proc.kill("SIGTERM")
|
||||||
await waitExit(proc)
|
await waitExit(proc)
|
||||||
}
|
}
|
||||||
if (proc.exitCode === null) {
|
if (!done(proc)) {
|
||||||
proc.kill("SIGKILL")
|
proc.kill("SIGKILL")
|
||||||
await waitExit(proc)
|
await waitExit(proc)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user