fix: address review of the Postgres move

- close the pool on SIGTERM before exiting; query_timeout on the pool
- SIGTERM test fails instead of hanging; test cleanup in finally
- preStop sleep so rollouts don't drop form posts; Postgres startupProbe
- CI step timeout, clear error if test Postgres never starts, remove test image
- export stops on SQL errors; README note on changing the DB password

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfmHGGiYUjNcvJoyzdf
This commit is contained in:
ngqileandClaude Opus 5.5 committed 2026-12-01 11:59:55 +08:00
1 parent 20e07e9d80
commit ad5996283e
7 files changed
+42 -14

No files matched your search

+5 -3
View File
@@ -70,7 +70,8 @@ async function createServer(databaseUrl) {
for (const [url, [file, type]] of Object.entries(PAGES)) {
files[url] = { body: fs.readFileSync(path.join(__dirname, 'public', file)), type };
}
const pool = new Pool({ connectionString: databaseUrl, max: 5, connectionTimeoutMillis: 5000 });
// query_timeout: a Postgres that accepts connections but never answers must not hang requests
const pool = new Pool({ connectionString: databaseUrl, max: 5, connectionTimeoutMillis: 5000, query_timeout: 10000 });
// an idle connection dropped by Postgres (restart, failover) must not crash the process
pool.on('error', (e) => console.error('postgres pool error:', e.message));
try {
@@ -113,7 +114,7 @@ async function createServer(databaseUrl) {
}
send(res, 404, { error: 'Not found' });
});
server.on('close', () => pool.end());
server.pool = pool; // callers end it after server.close (see SIGTERM below)
return server;
}
@@ -128,7 +129,8 @@ if (require.main === module) {
createServer(process.env.DATABASE_URL).then((server) => {
server.listen(port, () => console.log(`listening on :${port}`));
// node as PID 1 ignores SIGTERM by default; exit cleanly so k8s rollouts don't wait 30s
process.on('SIGTERM', () => server.close(() => process.exit(0)));
// finish in-flight requests, then close the database connections, then exit
process.on('SIGTERM', () => server.close(() => server.pool.end().finally(() => process.exit(0))));
}, (e) => {
// message only: the error never contains the password, but the URL would
console.error('startup failed:', e.message);