Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 0f7f211

Browse files
committed
Force exit workerd on exit hook
`exitHook()` must be synchronous, and we want to make sure `workerd` is cleaned up immediately on exit
1 parent 00f23af commit 0f7f211

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

packages/miniflare/src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,9 @@ export class Miniflare {
464464
verbose: this.#sharedOpts.core.verbose,
465465
};
466466
this.#runtime = new Runtime(opts);
467-
this.#removeRuntimeExitHook = exitHook(() => void this.#runtime?.dispose());
467+
this.#removeRuntimeExitHook = exitHook(
468+
() => void this.#runtime?.dispose(/* force */ true)
469+
);
468470

469471
// Update config and wait for runtime to start
470472
await this.#assembleAndUpdateConfig(/* initial */ true);

packages/miniflare/src/runtime/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,14 @@ export class Runtime {
134134
return this.#processExitPromise;
135135
}
136136

137-
dispose(): Awaitable<void> {
137+
dispose(force = false): Awaitable<void> {
138138
// `kill()` uses `SIGTERM` by default. In `workerd`, this waits for HTTP
139139
// connections to close before exiting. Notably, Chrome sometimes keeps
140140
// connections open for about 10s, blocking exit. We'd like `dispose()`/
141141
// `setOptions()` to immediately terminate the existing process.
142142
// Therefore, use `SIGINT` which force closes all connections.
143143
// See https://github.com/cloudflare/workerd/pull/244.
144-
this.#process?.kill("SIGINT");
144+
this.#process?.kill(force ? "SIGKILL" : "SIGINT");
145145
return this.#processExitPromise;
146146
}
147147
}

0 commit comments

Comments
 (0)