From 12e7761f906444e2884c822886840f8518ef1090 Mon Sep 17 00:00:00 2001 From: rajanpanth Date: Mon, 20 Jul 2026 19:02:03 +0545 Subject: [PATCH] fix: avoid kill timeout exit delays --- lib/flow-control/kill-others.spec.ts | 16 ++++++++++++++++ lib/flow-control/kill-others.ts | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/flow-control/kill-others.spec.ts b/lib/flow-control/kill-others.spec.ts index df88a18c..a46038f6 100644 --- a/lib/flow-control/kill-others.spec.ts +++ b/lib/flow-control/kill-others.spec.ts @@ -133,3 +133,19 @@ it('force kills misbehaving processes after a timeout', () => { expect(commands[1].kill).toHaveBeenCalledWith('SIGKILL'); expect(commands[2].kill).toHaveBeenCalledTimes(1); }); + +it('does not keep the event loop alive while waiting to force kill', () => { + const setTimeoutSpy = vi.spyOn(globalThis, 'setTimeout'); + + createWithConditions(['failure'], { timeoutMs: 60_000 }).handle(commands); + assignProcess(commands[1]); + commands[0].close.next(createFakeCloseEvent({ exitCode: 1 })); + + const timeout = setTimeoutSpy.mock.results.at(-1)?.value as NodeJS.Timeout; + try { + expect(timeout.hasRef()).toBe(false); + } finally { + clearTimeout(timeout); + setTimeoutSpy.mockRestore(); + } +}); diff --git a/lib/flow-control/kill-others.ts b/lib/flow-control/kill-others.ts index 2b2786a1..5e0d6179 100644 --- a/lib/flow-control/kill-others.ts +++ b/lib/flow-control/kill-others.ts @@ -87,6 +87,6 @@ export class KillOthers implements FlowController { ); killableCommands.forEach((command) => command.kill('SIGKILL')); } - }, this.timeoutMs); + }, this.timeoutMs).unref(); } }