- pool.js: add pool.on('error') handler — an idle-client error (DB restart /
.215 failover) previously crashed the process (no 'error' listener → throw)
- context tool: project a SAFE_COLUMNS allow-list for resources (never the
monitoring/metadata JSON blobs); also add 'resource' to TABLE (was unhandled)
- applyPendingChange: guard the 'upsert' arm so a non-upsertable entity_type
fails with a clear ValidationError instead of a bare TypeError
Tests: pool_error, context (resource case), pending_extended_actions (guard).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
17 lines
516 B
JavaScript
17 lines
516 B
JavaScript
import pg from 'pg';
|
|
import 'dotenv/config';
|
|
import { log } from '../log.js';
|
|
|
|
export const pool = new pg.Pool({
|
|
connectionString: process.env.DATABASE_URL,
|
|
max: 10,
|
|
idleTimeoutMillis: 30_000
|
|
});
|
|
|
|
// An idle pooled client can emit 'error' (DB restart, replication failover on
|
|
// the .215 cluster). With no listener, EventEmitter throws and the process
|
|
// crashes. Log and let pg discard the dead client; the pool reconnects lazily.
|
|
pool.on('error', (err) => {
|
|
log.error({ err }, 'idle pg client error');
|
|
});
|