-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Connection leak? #1777
Comments
Can you identify which version exactly introduced the issue? So we can narrow down possible breaking changes. |
Not really as once the condition hits, we return a lot of errors on our APIs, which are used by customers. I'm trying to replica this in our staging environment or in specific integration tests, but haven't been lucky so far. |
Well, we'd need to know which version broke it, unless there is something wrong in your code. For example, sometimes developers use an obsolete approach to using connections, and once support of it is removed, upgrading the library may result in bugs like that. Also, it is a little confusing that you list several versions of |
Yes, those are only sub-dependencies, which have been updated from version x ~> version y. I listed them here as each of them could have potentially introduced this.
Absolutely, but afaik we only use https://github.com/vitaly-t/pg-promise#transactions with async/await or |
Misspelled - I meant
That's a good start 😄 I hope you will find from which version your code stopped working 😉 Maybe you've got a leech somewhere, like a module that after upgrading no longer releases connections correctly. |
I think I may be seeing something similar on Error: timeout exceeded when trying to connect
at Timeout.setTimeout [as _onTimeout] (/.../node_modules/pg-pool/index.js:178:27)
at ontimeout (timers.js:478:11)
at tryOnTimeout (timers.js:302:5)
at Timer.listOnTimeout (timers.js:262:5) if I have cron.js const { CronJob } = require('cron')
const { someJob } = require('./jobs')
new CronJob('*/30 * * * * *', someJob, null, true) jobs.js const { Pool } = require('pg')
// Passing `connectionTimeoutMillis: 5000` here makes it error out instead of hanging
const pool = new Pool()
const someJob = async () => {
// This is the line that hangs or errors on the second execution
let { rows } = await pool.query('...', [ ... ])
rows.forEach(row => {
let client = await pool.connect()
try {
await client.query('...')
await client.query('COMMIT')
} catch (err) {
await client.query('ROLLBACK')
}
})
} The above example is obviously contrived but it captures my underlying usage. I can try to throw together a reproducible repo but I'm not sure how what db would hit since I obviously can't expose the service I'm working on. Aside from this cron job, pools have worked fine for me throughout the rest of the application I'm building (a koa-based api). I have read through the docs to see if I'm missing some cleanup steps or something and tried a few things like |
The issue (for me at least) was that I wasn't calling I noticed this after seeing the default Error: You've exceeded the maximum number of clients in your pool. Make sure to call `client.release()` to release clients back into the pool and bump `max` to more than 10 if you actually need 10+ clients in the pool at once. |
@skipjack yes, we might have a similar missing release somewhere, but sadly I haven't found anything so far. Especially as usually (and before the upgrade) everything just works ™️ , but at some pointing something is killing the pool. Below an example of a process generally serving ~100-200 req/min until the pool is gone and only 500s caused by |
Found two potential candidates brianc/node-pg-pool#109 🎉 |
@johanneswuerbach nice. Yeah so I think we were running into the the same issue (the pool gets filled and then timeouts are thrown) but with different root causes. In my case, I was missing the |
We are running with brianc/node-pg-pool#109 in production now for some time and it looks like this fully resolved our issues. |
We are running latest versions of all libraries now and no longer see this issue. |
We recently updated some of our postgres client libraries and experience an almost total pool exhaustion roughly 2~3h are deploying the new version in production (never happened before) on 2 out of 20 DBs.
We updated the following libraries.
pg 7.4.3 ~> 7.6.1
pg-pool 2.0.3 ~> 2.0.4
pg-promise 7.5.4 ~> 8.5.2
Once the pool is slowly exhausting a majority of queries hitting an affected process are returned with "timeout exceeded when trying to connect" https://github.com/brianc/node-pg-pool/blob/v2.0.4/index.js#L178 and the percentage is increasing overtime and condition is persistent (~30min until revert)
I'm debugging this for multiple days now, but have a hard time identifying the exact root cause, so far suspected:
brianc/node-pg-pool#86, which means we generally queue more work now as no longer all pending queue items are dropped, but we rarely saw "timeout exceeded when trying to connect" errors before so this seems unlikely
#1503 some kind of race condition here as both affected DBs occasionally are hit by queries running into statement timeouts.
Any ideas, pointer, potential areas for races would be really appreciated.
//cc @vitaly-t I know that pg-promise is not part of
pg
distribution, but you seemed really active here and I would prefer a single spot for discussion. Any insight would be appreciated.We mainly (but not exclusively) use nested transactions via https://github.com/vitaly-t/pg-promise#transactions starting with
SET LOCAL statement_timeout = 30000;
The text was updated successfully, but these errors were encountered: