brianc / node-pg-pool

A connection pool for node-postgres
MIT License
180 stars 64 forks source link

Getting stuck #91

Closed pencilcheck closed 6 years ago

pencilcheck commented 6 years ago
    const client = await pool.connect()

This line always get stuck especially when used in conjunction with queue management such as Automattic/kue

I really don't know how to debug this but whenever I use the recommended design to only create one pool and then do the pool.connect() then client.release(), the pool.connect always start to get stuck after leaving it running for a couple hours.

However if I don't use a global pool and instead create a new one on every new task, it will never get stuck.

charmander commented 6 years ago

Try logging the number of clients in the pool before every connection. (console.log(pool.totalCount)) If you’re using one client at a time, it should stay at 1. If you can find an action that causes it to continue increasing, you’re likely forgetting to call client.release() on that path.

pencilcheck commented 6 years ago

it is undefined for all of them.

charmander commented 6 years ago

Are you using the most recent versions of pg and pg-pool? Try upgrading.

pencilcheck commented 6 years ago

the pool was conflicting with another I used (postgraphql) that uses a older version. I noticed that and force install the latest version.

This still stuck when using kue randomly after letting it run a couple hours.

charmander commented 6 years ago

But now console.log(pool.totalCount) as described above shows…?

pencilcheck commented 6 years ago

Found a workaround (not a solution) to this issue but I think it can be justified to be closed.

I think I just found out that I simply have to clear finished tasks (perhaps overflowing the redis instance? but heroku redis free plan can only host 3000 tasks?), making the tasks retry 50 times, and also putting stuck jobs into "inactive" queue and somehow makes the task flow better now.