postgres: ECONNRESET errors after a while
Hi @porsager !
Similar to #43, I’m also encountering similar ECONNRESET
errors with a PostgreSQL service on Render.com, but with a very low number of connections:
Apr 27 10:22:53 PM node:internal/process/promises:246
Apr 27 10:22:53 PM triggerUncaughtException(err, true /* fromPromise */);
Apr 27 10:22:53 PM ^
Apr 27 10:22:53 PM
Apr 27 10:22:53 PM Error: read ECONNRESET at TCP.onStreamRead (node:internal/stream_base_commons:211:20) {
Apr 27 10:22:53 PM errno: -104,
Apr 27 10:22:53 PM code: 'ECONNRESET',
Apr 27 10:22:53 PM syscall: 'read'
Apr 27 10:22:53 PM }
Apr 27 10:22:54 PM error Command failed with exit code 1.
It seems like after a certain amount of time, the connection with PostgreSQL goes into this state where the ECONNRESET
errors start happening. Once it’s in that state, it fails all queries for a while (a few minutes?). But then it eventually “wakes up” again (I guess Postgres.js eventually figured it out and reconnected at that point).
I’m using postgres@2.0.0-beta.5
- I’m assuming this beta version is not super unstable like this…? I never had any issues with this with Heroku’s PostgreSQL service.
I’ve also asked for assistance from the Render.com support team over here: https://community.render.com/t/econnreset-with-node-js-and-postgresql/1498
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 1
- Comments: 17 (16 by maintainers)
Maybe I’ll wait for this feature to land in non-beta v2 and then we can close this.
Ok, some updates:
connect_timeout: 10
had no effectidle_timeout: 2
has the service working again now 🤯So I guess Render.com terminates idle PostgreSQL connections on the server side… I’ll ask about this on the community page.
Maybe a good thing to add to the Postgres.js docs too, in case this is a more common configuration…
I’ve just released beta.6 which simply sets keepalive from the client to 60 seconds (a postgres db connection is fairly high bandwidth already, so I feel 60 seconds is a good start). I’m curious if something as simple as this will do? Would you mind giving it a go?
If not we could look into doing like the go library, which appears to retry if this connection failure happens.
Hi Karl.
Yeah, this is probably a common scenario.
Could be included with the part you already contributed about lambdas etc. 🙂 https://github.com/porsager/postgres#idle-timeout