From 77039044ebd74b907a44a08ae5421517fc74b46e Mon Sep 17 00:00:00 2001 From: Michael Kret <88898367+michael-radency@users.noreply.github.com> Date: Thu, 12 Oct 2023 12:10:14 +0300 Subject: [PATCH] fix(core): Pg-promise de-initialization fix (#7417) Github issue / Community forum post (link here to close automatically): https://community.n8n.io/t/postgres-node-called-end-on-pool-more-than-once/30585/1 --- packages/nodes-base/nodes/CrateDb/CrateDb.node.ts | 6 +++--- .../nodes-base/nodes/Microsoft/Sql/MicrosoftSql.node.ts | 2 +- .../nodes/Postgres/PostgresTrigger.functions.ts | 8 ++++---- .../nodes-base/nodes/Postgres/PostgresTrigger.node.ts | 4 ++-- packages/nodes-base/nodes/Postgres/v1/PostgresV1.node.ts | 8 ++++---- packages/nodes-base/nodes/QuestDb/QuestDb.node.ts | 6 +++--- packages/nodes-base/nodes/TimescaleDb/TimescaleDb.node.ts | 6 +++--- 7 files changed, 20 insertions(+), 20 deletions(-) diff --git a/packages/nodes-base/nodes/CrateDb/CrateDb.node.ts b/packages/nodes-base/nodes/CrateDb/CrateDb.node.ts index 79cd22c8db..b0e6dab6c9 100644 --- a/packages/nodes-base/nodes/CrateDb/CrateDb.node.ts +++ b/packages/nodes-base/nodes/CrateDb/CrateDb.node.ts @@ -378,15 +378,15 @@ export class CrateDb implements INodeType { returnItems = this.helpers.returnJsonArray(getItemsCopy(items, columns)); } } else { - pgp.end(); + await db.$pool.end(); throw new NodeOperationError( this.getNode(), `The operation "${operation}" is not supported!`, ); } - // Close the connection - pgp.end(); + // shuts down the connection pool associated with the db object to allow the process to finish + await db.$pool.end(); return [returnItems]; } diff --git a/packages/nodes-base/nodes/Microsoft/Sql/MicrosoftSql.node.ts b/packages/nodes-base/nodes/Microsoft/Sql/MicrosoftSql.node.ts index f91a5dc9ad..7bbf15519a 100644 --- a/packages/nodes-base/nodes/Microsoft/Sql/MicrosoftSql.node.ts +++ b/packages/nodes-base/nodes/Microsoft/Sql/MicrosoftSql.node.ts @@ -440,7 +440,7 @@ export class MicrosoftSql implements INodeType { } } - // Close the connection + // shuts down the connection pool associated with the db object to allow the process to finish await pool.close(); const itemData = generatePairedItemData(items.length); diff --git a/packages/nodes-base/nodes/Postgres/PostgresTrigger.functions.ts b/packages/nodes-base/nodes/Postgres/PostgresTrigger.functions.ts index 9d6ea69c78..e27b863b42 100644 --- a/packages/nodes-base/nodes/Postgres/PostgresTrigger.functions.ts +++ b/packages/nodes-base/nodes/Postgres/PostgresTrigger.functions.ts @@ -112,19 +112,19 @@ export async function initDB(this: ITriggerFunctions | ILoadOptionsFunctions) { } export async function searchSchema(this: ILoadOptionsFunctions): Promise { - const { db, pgp } = await initDB.call(this); + const { db } = await initDB.call(this); const schemaList = await db.any('SELECT schema_name FROM information_schema.schemata'); const results: INodeListSearchItems[] = (schemaList as IDataObject[]).map((s) => ({ name: s.schema_name as string, value: s.schema_name as string, })); - pgp.end(); + await db.$pool.end(); return { results }; } export async function searchTables(this: ILoadOptionsFunctions): Promise { const schema = this.getNodeParameter('schema', 0) as IDataObject; - const { db, pgp } = await initDB.call(this); + const { db } = await initDB.call(this); let tableList = []; try { tableList = await db.any( @@ -138,6 +138,6 @@ export async function searchTables(this: ILoadOptionsFunctions): Promise