Skip to content

fix: PoolClient leak after an error in PostgresDriver#45

Open
drauggres wants to merge 1 commit inton8n-io:masterfrom
drauggres:fix-pq-connection-leak
Open

fix: PoolClient leak after an error in PostgresDriver#45
drauggres wants to merge 1 commit inton8n-io:masterfrom
drauggres:fix-pq-connection-leak

Conversation

@drauggres
Copy link

@drauggres drauggres commented Feb 10, 2026

After an error, the PoolClient was not released. This was causing the broken connection to be reused. When multiple servers were specified in the connection string, leaked PoolClient prevented connection to another server.

Pull-Request Checklist

  • Code is up-to-date with the master branch
  • npm run format to apply prettier formatting
  • npm run test passes with this change
  • This pull request links relevant issues as Fixes #0000 (N/A)
  • There are new or updated unit tests validating the change (N/A)
  • Documentation has been updated to reflect this change (N/A)
  • The new commits follow conventions explained in CONTRIBUTING.md

Summary by cubic

Fixes a connection leak in PostgresDriver by releasing the PoolClient on connection errors. This prevents reusing broken connections and restores failover when multiple hosts are in the connection string.

  • Bug Fixes
    • Release PoolClient on "error" and log a warning.
    • Remove "error" and "release" listeners after client release.

Written for commit 40ab31f. Summary will update on new commits.

After an error, the PoolClient was not released. This was causing the broken
connection to be reused. When multiple servers were specified in the connection
string, leaked PoolClient prevented connection to another server.
Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 1 file

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="src/driver/postgres/PostgresDriver.ts">

<violation number="1" location="src/driver/postgres/PostgresDriver.ts:1200">
P1: Connection and listener leak when initialization queries throw: connection is never released and attached listeners stay registered.</violation>
</file>

Since this is your first cubic review, here's how it works:

  • cubic automatically reviews your code and comments on bugs and improvements
  • Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
  • Add one-off context when rerunning by tagging @cubic-dev-ai with guidance or docs links (including llms.txt)
  • Ask questions if you need clarification on any suggestion

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

}
}
connection.on("error", onError)
master.on("release", onRelease)
Copy link

@cubic-dev-ai cubic-dev-ai bot Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: Connection and listener leak when initialization queries throw: connection is never released and attached listeners stay registered.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/driver/postgres/PostgresDriver.ts, line 1200:

<comment>Connection and listener leak when initialization queries throw: connection is never released and attached listeners stay registered.</comment>

<file context>
@@ -1180,6 +1180,24 @@ export class PostgresDriver implements Driver {
+            }
+        }
+        connection.on("error", onError)
+        master.on("release", onRelease)
         const { schema } = this.options
         if (schema && schema !== "public") {
</file context>
Fix with Cubic

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant