Skip to content

fix: release the connection when a transaction fails to start - #839

Open
felipera87 wants to merge 2 commits into
loopbackio:masterfrom
PruvoNet:fix/release-connection-on-failed-transaction-start
Open

felipera87 wants to merge 2 commits into
loopbackio:masterfrom
PruvoNet:fix/release-connection-on-failed-transaction-start

Conversation

@felipera87

Copy link
Copy Markdown

When SET TRANSACTION ISOLATION LEVEL or BEGIN fails, beginTransaction calls back with the error but never releases the connection it took from the pool. Each failed start keeps one connection for good, so a few of them drain the pool and every later query waits forever.

We hit this in production. Our database refused a burst of SET SESSION TRANSACTION statements while it was low on memory, every pooled connection leaked, and requests hung until the HTTP timeout.

The fix releases the connection on the three error paths. The new tests use a pool with a single connection and check that a follow-up query still runs after a failed start. They fail on master.

beginTransaction called cb(err) without connection.release() when
SET TRANSACTION ISOLATION LEVEL or BEGIN failed, so every failed
start kept a pooled connection for good. A few of them drain the
pool and every later query waits for ever.

Signed-off-by: Felipe Reis <felipe@pruvo.com>
Signed-off-by: Felipe Reis <felipe@pruvo.com>
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