mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-25 20:54:07 -08: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:
parent
2b6a15e478
commit
77039044eb
|
@ -378,15 +378,15 @@ export class CrateDb implements INodeType {
|
||||||
returnItems = this.helpers.returnJsonArray(getItemsCopy(items, columns));
|
returnItems = this.helpers.returnJsonArray(getItemsCopy(items, columns));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
pgp.end();
|
await db.$pool.end();
|
||||||
throw new NodeOperationError(
|
throw new NodeOperationError(
|
||||||
this.getNode(),
|
this.getNode(),
|
||||||
`The operation "${operation}" is not supported!`,
|
`The operation "${operation}" is not supported!`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close the connection
|
// shuts down the connection pool associated with the db object to allow the process to finish
|
||||||
pgp.end();
|
await db.$pool.end();
|
||||||
|
|
||||||
return [returnItems];
|
return [returnItems];
|
||||||
}
|
}
|
||||||
|
|
|
@ -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();
|
await pool.close();
|
||||||
|
|
||||||
const itemData = generatePairedItemData(items.length);
|
const itemData = generatePairedItemData(items.length);
|
||||||
|
|
|
@ -112,19 +112,19 @@ export async function initDB(this: ITriggerFunctions | ILoadOptionsFunctions) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function searchSchema(this: ILoadOptionsFunctions): Promise<INodeListSearchResult> {
|
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 schemaList = await db.any('SELECT schema_name FROM information_schema.schemata');
|
||||||
const results: INodeListSearchItems[] = (schemaList as IDataObject[]).map((s) => ({
|
const results: INodeListSearchItems[] = (schemaList as IDataObject[]).map((s) => ({
|
||||||
name: s.schema_name as string,
|
name: s.schema_name as string,
|
||||||
value: s.schema_name as string,
|
value: s.schema_name as string,
|
||||||
}));
|
}));
|
||||||
pgp.end();
|
await db.$pool.end();
|
||||||
return { results };
|
return { results };
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function searchTables(this: ILoadOptionsFunctions): Promise<INodeListSearchResult> {
|
export async function searchTables(this: ILoadOptionsFunctions): Promise<INodeListSearchResult> {
|
||||||
const schema = this.getNodeParameter('schema', 0) as IDataObject;
|
const schema = this.getNodeParameter('schema', 0) as IDataObject;
|
||||||
const { db, pgp } = await initDB.call(this);
|
const { db } = await initDB.call(this);
|
||||||
let tableList = [];
|
let tableList = [];
|
||||||
try {
|
try {
|
||||||
tableList = await db.any(
|
tableList = await db.any(
|
||||||
|
@ -138,6 +138,6 @@ export async function searchTables(this: ILoadOptionsFunctions): Promise<INodeLi
|
||||||
name: s.table_name as string,
|
name: s.table_name as string,
|
||||||
value: s.table_name as string,
|
value: s.table_name as string,
|
||||||
}));
|
}));
|
||||||
pgp.end();
|
await db.$pool.end();
|
||||||
return { results };
|
return { results };
|
||||||
}
|
}
|
||||||
|
|
|
@ -224,7 +224,7 @@ export class PostgresTrigger implements INodeType {
|
||||||
const additionalFields = this.getNodeParameter('additionalFields', 0) as IDataObject;
|
const additionalFields = this.getNodeParameter('additionalFields', 0) as IDataObject;
|
||||||
|
|
||||||
// initialize and connect to database
|
// 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 });
|
const connection = await db.connect({ direct: true });
|
||||||
|
|
||||||
// prepare and set up listener
|
// prepare and set up listener
|
||||||
|
@ -284,7 +284,7 @@ export class PostgresTrigger implements INodeType {
|
||||||
`Postgres Trigger Error: ${(error as Error).message}`,
|
`Postgres Trigger Error: ${(error as Error).message}`,
|
||||||
);
|
);
|
||||||
} finally {
|
} finally {
|
||||||
pgp.end();
|
await db.$pool.end();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -323,7 +323,7 @@ export class PostgresV1 implements INodeType {
|
||||||
|
|
||||||
const db = pgp(config);
|
const db = pgp(config);
|
||||||
await db.connect();
|
await db.connect();
|
||||||
pgp.end();
|
await db.$pool.end();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return {
|
return {
|
||||||
status: 'Error',
|
status: 'Error',
|
||||||
|
@ -412,15 +412,15 @@ export class PostgresV1 implements INodeType {
|
||||||
|
|
||||||
returnItems = wrapData(updateItems);
|
returnItems = wrapData(updateItems);
|
||||||
} else {
|
} else {
|
||||||
pgp.end();
|
await db.$pool.end();
|
||||||
throw new NodeOperationError(
|
throw new NodeOperationError(
|
||||||
this.getNode(),
|
this.getNode(),
|
||||||
`The operation "${operation}" is not supported!`,
|
`The operation "${operation}" is not supported!`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close the connection
|
// shuts down the connection pool associated with the db object to allow the process to finish
|
||||||
pgp.end();
|
await db.$pool.end();
|
||||||
|
|
||||||
return [returnItems];
|
return [returnItems];
|
||||||
}
|
}
|
||||||
|
|
|
@ -256,15 +256,15 @@ export class QuestDb implements INodeType {
|
||||||
|
|
||||||
returnItems = this.helpers.returnJsonArray(insertData);
|
returnItems = this.helpers.returnJsonArray(insertData);
|
||||||
} else {
|
} else {
|
||||||
pgp.end();
|
await db.$pool.end();
|
||||||
throw new NodeOperationError(
|
throw new NodeOperationError(
|
||||||
this.getNode(),
|
this.getNode(),
|
||||||
`The operation "${operation}" is not supported!`,
|
`The operation "${operation}" is not supported!`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close the connection
|
// shuts down the connection pool associated with the db object to allow the process to finish
|
||||||
pgp.end();
|
await db.$pool.end();
|
||||||
|
|
||||||
return [returnItems];
|
return [returnItems];
|
||||||
}
|
}
|
||||||
|
|
|
@ -320,15 +320,15 @@ export class TimescaleDb implements INodeType {
|
||||||
|
|
||||||
returnItems = this.helpers.returnJsonArray(updateItems);
|
returnItems = this.helpers.returnJsonArray(updateItems);
|
||||||
} else {
|
} else {
|
||||||
pgp.end();
|
await db.$pool.end();
|
||||||
throw new NodeOperationError(
|
throw new NodeOperationError(
|
||||||
this.getNode(),
|
this.getNode(),
|
||||||
`The operation "${operation}" is not supported!`,
|
`The operation "${operation}" is not supported!`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close the connection
|
// shuts down the connection pool associated with the db object to allow the process to finish
|
||||||
pgp.end();
|
await db.$pool.end();
|
||||||
|
|
||||||
return [returnItems];
|
return [returnItems];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue