Hi there,
I got some issues with this pool.
Maybe this is related to brianc/node-postgres#1790 and brianc/node-postgres#1611.
First of all this is my environment:
- node-postgres@7.7.1
- pg-pool@2.0.5
- NodeJS v10.15.0
- PostgreSQL 10.6 (hosted by Aiven.io [50 connections])
I'm using pg-pool with this config:
{
/* normal credentials with ssl */
min: 10,
max: 46,
idleTimeoutMillis: 30000,
connectionTimeoutMillis: 3000
}
I get about 10 times a day this error:
Connection terminated due to connection timeout.
This leads to a failure of some query and thus to an error for the end-user.
I already tried to debug this in cooperation with my Database-Provider, however this doesn't seem to be related to that. The ping to my db is about 0.23ms in the same data-center.
After having a look at the code, enabling detailed logging and hours of debugging I think I found the issue.
I think this is related to ending clients on idle timeouts:
https://github.com/brianc/node-pg-pool/blob/master/index.js#L41
Here the idle timeout is triggered, however it does not check if the client is currently used. I know the timeout is cleared in https://github.com/brianc/node-pg-pool/blob/master/index.js#L138, but there seems to be an edge case where a client gets destroyed, which has just been given to the application.
For me that happened once in about 2000 requests.
To prove my intention, I set idleTimeoutMillis to 0, which disables the removal of idle clients. This solved the issue for me. I never got this error again.
I cannot really say how this can happen nor how to fix it, but I'm pretty sure this is related to the idle-timeout.
Hope this helps debugging it.
Have a nice day,
Dustin