How to end pool connections

Hi, I’m writing some integration tests that involve me spinning up a postgis docker container and then tearing it down. However in the teardown step I keep getting this error that leads me to think I need to close the my pg drizzle pool connections before i close my app. I’m wondering if there’s a way to close my NodePgSession? I can’t seem to find any documentation or issues that have this error. Error: Unhandled error. ({ code: 'ERR_UNHANDLED_ERROR', context: error: terminating connection due to administrator command    at Parser.parseErrorMessage (/node_modules/pg-protocol/src/parser.ts:369:69)    at Parser.handlePacket (/node_modules/pg-protocol/src/parser.ts:188:21)    at Parser.parse (/node_modules/pg-protocol/src/parser.ts:103:30)    at Socket.<anonymous> (/node_modules/pg-protocol/src/index.ts:7:48) length: 116, severity: 'FATAL', code: '57P01', detail: undefined, hint: undefined, position: undefined, internalPosition: undefined, internalQuery: undefined, where: undefined, schema: undefined, table: undefined, column: undefined, dataType: undefined, constraint: undefined, file: 'postgres.c', line: '3094', routine: 'ProcessInterrupts', client: Client {    _events: [Object: null prototype],    _eventsCount: 1,    _maxListeners: undefined,    connectionParameters: [ConnectionParameters],    user: 'testUser',    database: 'testDb',    port: 5432,    host: 'localhost',    replication: undefined,    _Promise: [Function: Promise],    _types: [TypeOverrides],    _ending: true,    _ended: false,    _connecting: false,    _connected: true,    _connectionError: false,    _queryable: false,    connection: [Connection],    queryQueue: [],    binary: false,    processID: 345,    secretKey: -1006417647,    ssl: false,    _connectionTimeoutMillis: 0,    _connectionCallback: null,    release: [Function (anonymous)],    activeQuery: null,    readyForQuery: true,    hasExecuted: true,    _poolUseCount: 20,    [Symbol(kCapture)]: false } }
2 Replies
baronnoraz
baronnoraz9mo ago
I haven't used PostgreSQL with Drizzle yet, but I imagine it's something like...
const client = new Client(...);
await client.connect();
const db = drizzle(client);

// then in your afterAll or something...
client.end()
const client = new Client(...);
await client.connect();
const db = drizzle(client);

// then in your afterAll or something...
client.end()
At least that seems to be how the node-postgres driver has it, https://node-postgres.com/apis/client. But I may not be understanding what you're asking. I know Jest complains if I don't close the client connection in this way for MySQL.
hdawg
hdawg9mo ago
It ended up being something similar, i just had to configure my pgpool to allowExitOnIdle and then to set the idleTimeoutMillis to something small. Thanks! I would consider this help ticket resolved
Want results from more Discord servers?
Add your server