-
Notifications
You must be signed in to change notification settings - Fork 13.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(Postgres Node): Backport connection pooling to postgres v1 #12484
Changes from all commits
e3e8552
72bfd01
240877b
82f2a38
a0bd8e5
9ce7027
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,23 +4,21 @@ import type { | |
INodeCredentialTestResult, | ||
} from 'n8n-workflow'; | ||
|
||
import type { PgpClient, PostgresNodeCredentials } from '../helpers/interfaces'; | ||
import { configurePostgres } from '../transport'; | ||
import { configurePostgres } from '../../transport'; | ||
import type { PgpConnection, PostgresNodeCredentials } from '../helpers/interfaces'; | ||
|
||
export async function postgresConnectionTest( | ||
this: ICredentialTestFunctions, | ||
credential: ICredentialsDecrypted, | ||
): Promise<INodeCredentialTestResult> { | ||
const credentials = credential.data as PostgresNodeCredentials; | ||
|
||
let pgpClientCreated: PgpClient | undefined; | ||
let connection: PgpConnection | undefined; | ||
|
||
try { | ||
const { db, pgp } = await configurePostgres.call(this, credentials, {}); | ||
const { db } = await configurePostgres.call(this, credentials, {}); | ||
|
||
pgpClientCreated = pgp; | ||
|
||
await db.connect(); | ||
connection = await db.connect(); | ||
} catch (error) { | ||
let message = error.message as string; | ||
|
||
|
@@ -41,8 +39,8 @@ export async function postgresConnectionTest( | |
message, | ||
}; | ||
} finally { | ||
if (pgpClientCreated) { | ||
pgpClientCreated.end(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would shut down all pools in the process:
Doing this would render any pool for any credential unusable until restarting n8n or waiting for the pool to be destroyed by the connection pool manager and every execution would throw this: |
||
if (connection) { | ||
await connection.done(); | ||
} | ||
} | ||
return { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would have left the connection hanging. It needs to be ended:
https://vitaly-t.github.io/pg-promise/Database.html#connect