1
1
mirror of https://github.com/n8n-io/n8n.git synced 2024-09-20 09:27:44 +03:00

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
This commit is contained in:
Michael Kret 2023-10-12 12:10:14 +03:00 committed by GitHub
parent 2b6a15e478
commit 77039044eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 20 additions and 20 deletions

View File

@ -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];
}

View File

@ -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);

View File

@ -112,19 +112,19 @@ export async function initDB(this: ITriggerFunctions | ILoadOptionsFunctions) {
}
export async function searchSchema(this: ILoadOptionsFunctions): Promise<INodeListSearchResult> {
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<INodeListSearchResult> {
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<INodeLi
name: s.table_name as string,
value: s.table_name as string,
}));
pgp.end();
await db.$pool.end();
return { results };
}

View File

@ -224,7 +224,7 @@ export class PostgresTrigger implements INodeType {
const additionalFields = this.getNodeParameter('additionalFields', 0) as IDataObject;
// initialize and connect to database
const { db, pgp } = await initDB.call(this);
const { db } = await initDB.call(this);
const connection = await db.connect({ direct: true });
// prepare and set up listener
@ -284,7 +284,7 @@ export class PostgresTrigger implements INodeType {
`Postgres Trigger Error: ${(error as Error).message}`,
);
} finally {
pgp.end();
await db.$pool.end();
}
};

View File

@ -323,7 +323,7 @@ export class PostgresV1 implements INodeType {
const db = pgp(config);
await db.connect();
pgp.end();
await db.$pool.end();
} catch (error) {
return {
status: 'Error',
@ -412,15 +412,15 @@ export class PostgresV1 implements INodeType {
returnItems = wrapData(updateItems);
} 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];
}

View File

@ -256,15 +256,15 @@ export class QuestDb implements INodeType {
returnItems = this.helpers.returnJsonArray(insertData);
} 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];
}

View File

@ -320,15 +320,15 @@ export class TimescaleDb implements INodeType {
returnItems = this.helpers.returnJsonArray(updateItems);
} 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];
}