From ded2a472bcce61147979e1973d592c294310743f Mon Sep 17 00:00:00 2001 From: Johannes Fleck Date: Thu, 12 Nov 2026 10:22:27 +0100 Subject: [PATCH] fix(server): Close the database pool on shutdown adapter-node stops the HTTP server on SIGTERM/SIGINT but lets the process exit on its own. Nothing called closeDb(), so the idle pool connections kept the process alive for idleTimeoutMillis (30 s) after every shutdown: pods took about as long as the default termination grace period to stop, and the E2E teardown waited 30 s for the app to exit. Close the pool on sveltekit:shutdown, which fires after all in-flight requests completed. --- src/hooks.server.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/hooks.server.ts b/src/hooks.server.ts index d5a62a99..fed2d46b 100644 --- a/src/hooks.server.ts +++ b/src/hooks.server.ts @@ -26,6 +26,7 @@ import '$lib/server/trino/config.js'; import { storageEncryptionKey } from '$lib/server/storage/encryption-key.js'; import { notConnected } from '$lib/server/storage/not-connected.js'; import { runMigrations } from '$lib/server/migrate.js'; +import { closeDb } from '$lib/server/db.js'; // Allow self-signed TLS certificates in development (e.g. local Trino with self-signed certs). if (dev) { @@ -176,6 +177,10 @@ export const init: ServerInit = async () => { if (storageBrowserEnabled) { storageEncryptionKey(); // throws immediately if the env var is missing/invalid } + // adapter-node stops the HTTP server on SIGTERM/SIGINT but leaves the process + // to exit on its own; idle pool connections would keep it alive for + // idleTimeoutMillis. + process.once('sveltekit:shutdown', () => void closeDb()); }; export const handleError: HandleServerError = ({ error, event, status, message }) => {