Skip to content

Commit 80e967e

Browse files
committed
fix(graphile-schema): route buildSchemaSDL pool through pg-cache for proper cleanup
Previously, buildSchemaSDL let makePgService create its own internal pg Pool using a connection string. This pool was not tracked by pg-cache, so when ephemeral database teardown called pgCache.delete() + dropdb, PostGraphile's pool connections remained open, causing: - 'database has active sessions' errors on dropdb - pg_terminate_backend killing those connections - 'terminating connection due to administrator command' (57P01) errors bubbling up to the user Fix: Create the pool via getPgPool() (which registers it in pgCache) and pass it directly to makePgService. Now the existing cleanup code in pgpm-module.ts and generate.ts (pgCache.delete + waitForDisposals) properly closes the PostGraphile pool before dropping the ephemeral database.
1 parent d7ad4d8 commit 80e967e

1 file changed

Lines changed: 8 additions & 9 deletions

File tree

graphile/graphile-schema/src/build-schema.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import deepmerge from 'deepmerge'
22
import { printSchema } from 'graphql'
33
import { ConstructivePreset, makePgService } from 'graphile-settings'
44
import { makeSchema } from 'graphile-build'
5-
import { buildConnectionString } from 'pg-cache'
5+
import { getPgPool } from 'pg-cache'
66
import { getPgEnvOptions } from 'pg-env'
77
import type { GraphileConfig } from 'graphile-config'
88

@@ -17,19 +17,18 @@ export async function buildSchemaSDL(opts: BuildSchemaOptions): Promise<string>
1717
const schemas = Array.isArray(opts.schemas) ? opts.schemas : []
1818

1919
const config = getPgEnvOptions({ database })
20-
const connectionString = buildConnectionString(
21-
config.user,
22-
config.password,
23-
config.host,
24-
config.port,
25-
config.database,
26-
)
20+
21+
// Create the pool through pg-cache so it is tracked and can be cleaned up
22+
// by callers via pgCache.delete(database) before dropping ephemeral databases.
23+
// Without this, makePgService creates its own internal pool that isn't released,
24+
// causing "database has active sessions" errors during ephemeral DB teardown.
25+
const pool = getPgPool(config)
2726

2827
const basePreset: GraphileConfig.Preset = {
2928
extends: [ConstructivePreset],
3029
pgServices: [
3130
makePgService({
32-
connectionString,
31+
pool,
3332
schemas,
3433
}),
3534
],

0 commit comments

Comments
 (0)