-
Notifications
You must be signed in to change notification settings - Fork 275
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
ECONNRESET errors after a while #179
Comments
If the connection is being terminated after a while of inactivity, maybe another option would be to try the |
Seems like Render.com is still on PostgreSQL 11.7 (maybe to be upgraded in the summer), although I guess that would not be the cause... |
Ok, some updates:
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... |
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 |
Ok, I've added a quick note there then: #180 I guess closing this issue for now, since there's nothing else that's really actionable unless there's more info from the Render.com support team. |
So @joshi4 from the Render.com team helped with debugging the issue more on the topic I opened on the community site. Copying here for visibility:
What I ended up with was this configuration (2 hour idle timeout), which seems to work so far: const sql = postgres({ idle_timeout: 7200 }); |
Updates:
|
Update: Just had another issue with This is unfortunate that we cannot keep a persistent connection to the database with Render.com PostgreSQL. |
Following up from Karl's original issue. I wanted to summarize a few of my observations based on the code in the following two repositories: I created a database in Render's Europe region and deployed both the above repos as background workers. For the postgresjs-conn-test repo, I was able to consistently trigger the ECONNRESET log by setting the I have yet to see a similar error in the conn-reset-go service. Both apps are pointing at the exact same database and make the same number of requests in the same time intervals. I also tested the same setup in Render's US region and I haven't been able to replicate the issue there across both Node and Go apps. Putting everything together, it seems to me that the most robust solution seems to be to handle this on the client side. I notice that Go's standard library does account for such behavior here: // QueryContext executes a query that returns rows, typically a SELECT.
// The args are for any placeholder parameters in the query.
func (db *DB) QueryContext(ctx context.Context, query string, args ...interface{}) (*Rows, error) {
var rows *Rows
var err error
for i := 0; i < maxBadConnRetries; i++ {
rows, err = db.query(ctx, query, args, cachedOrNewConn)
if err != driver.ErrBadConn {
break
}
}
if err == driver.ErrBadConn {
return db.query(ctx, query, args, alwaysNewConn)
}
return rows, err
} This issue might also be related to: #121 Note: I currently work at Render. |
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. |
Nice! Going to deploy a new version with |
It depends on the idle handling on the server you connect to. If there's a load balancer in between (eg. pgbouncer) it might not respect tcp keep alives, but only care about timeout after no queries (i don't know, but you could most likely find that information somewhere). If my understanding of the issue is correct, what happens is that the server closes the tcp socket abruptly, so that the connected Postgres.js client doesn't know it's gone. Then when the next query is executed an error is returned when trying to write because the connection is closed, and hence the query errors. Now if the server has a rule that it always closes a connection after a specific amount of time (regardless of idle time) there's not much else we can do but try to reconnect on failure. That would require some logic around backoff + retries, but it's definitely doable. |
Ok, |
Haven't had any issues since the deploy... I'll keep watching! |
That's great @karlhorky - Thanks for testing! |
Still no incidents since the deploy (21 days now) |
Maybe I'll wait for this feature to land in non-beta v2 and then we can close this. |
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: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
The text was updated successfully, but these errors were encountered: