MatteoGioioso / serverless-pg

A package for managing PostgreSQL connections at SERVERLESS scale
MIT License
321 stars 16 forks source link

Clean function does not handle "idle in transaction" and "idle in transaction (aborted)" connections states #89

Open iOrcohen opened 1 year ago

iOrcohen commented 1 year ago

Currently, the clean function in our application does not properly handle connections in the "idle in transaction" and "idle in transaction (aborted)" states, leading to potential issues and resource leaks. This problem occurs when connections are left open but not actively executing any queries, resulting in a waste of system resources and potential conflicts.

To address this problem, we need to update the clean function to properly handle these connection states. The function should be able to identify and close connections that are stuck in either "idle in transaction" or "idle in transaction (aborted)" states, ensuring that our application maintains a healthy and efficient connection pool.

We are solving this issue right now by creating a patch for the NPM with the following changes in the code -

in 3 occurrences in src/index.js -

AND state = 'idle'

Changed to -

AND state in ('idle', 'idle in transaction', 'idle in transaction (aborted)', 'disabled')
MatteoGioioso commented 1 year ago

Thanks for reporting this issue. I think we could do this, but I would prefer pass it as an option.

iOrcohen commented 1 year ago

Thanks for the quick answer ! I would be love to open a PR if you like, with the option to enable this.

MatteoGioioso commented 1 year ago

Sure, a PR would be highly appreciated :pray:

Could you please explain how would you like to approach this? I was thinking to pass an array additionalConnectionsState: ['idle in transaction', 'idle in transaction (aborted)', 'disabled'], but feel free to suggest whatever works best.