fix(db): defer process.exit(0) by a macrotask on graceful shutdown (#13306) (#13778)

Merged in the 2026-09-16 sweep of the maintainer's own open PRs, at the owner's explicit instruction. No push was made to the PR branch: the merge took the head as the owning session left it (verified OPEN, non-draft and MERGEABLE against the release tip immediately before merging).
This commit is contained in:
Diego Rodrigues de Sa e Souza
2026-09-16 06:15:31 -03:00
committed by GitHub
parent 0459c6dc0a
commit 74e44d7630
3 changed files with 101 additions and 1 deletions

View File

@@ -200,7 +200,16 @@ export function initGracefulShutdown(): void {
}
const shutdown = (signal: string) => {
void globalThis.__omnirouteRequestShutdown?.(signal).then(() => process.exit(0));
void globalThis.__omnirouteRequestShutdown?.(signal).then(() => {
// #13306: on Windows, sql.js's Emscripten WASM build leaves pending libuv
// async-handle teardown work in flight after a statement has run. Calling
// process.exit() in the same tick as cleanup() resolving tears the event loop
// down before that teardown settles, and libuv's Windows async-handle close path
// asserts `!(handle->flags & UV_HANDLE_CLOSING)` -> hard abort. Deferring by one
// macrotask (mirrors 9router's own shutdown call sites, e.g.
// appUpdater.js:199, cli/cli.js:675) gives that teardown work a chance to run.
setTimeout(() => process.exit(0), 0);
});
};
process.on("SIGTERM", () => void shutdown("SIGTERM"));