diff --git a/src/gateway/server-close.ts b/src/gateway/server-close.ts index ba8913ffab3..5e0311e6381 100644 --- a/src/gateway/server-close.ts +++ b/src/gateway/server-close.ts @@ -16,8 +16,12 @@ const HTTP_CLOSE_GRACE_MS = 1_000; const HTTP_CLOSE_FORCE_WAIT_MS = 5_000; function createTimeoutRace(timeoutMs: number, onTimeout: () => T) { - let timer: ReturnType | null = setTimeout(() => { - timer = null; + let timer: ReturnType | null = null; + timer = setTimeout(() => { + if (timer) { + clearTimeout(timer); + timer = null; + } resolve(onTimeout()); }, timeoutMs); timer.unref?.();