Skip to content
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

write: connection reset by peer should close the connection #1028

Closed
Sytten opened this issue Feb 18, 2021 · 7 comments
Closed

write: connection reset by peer should close the connection #1028

Sytten opened this issue Feb 18, 2021 · 7 comments

Comments

@Sytten
Copy link

Sytten commented Feb 18, 2021

Setup

I am using a serverless setup on GCP Cloud Run (knative) with a database in VPC accessed via a serverless connector.
This is a similar to a setup where a server communicates with a database behind an HAProxy or an NGINX.
The only difference is that if the server is not receiving requests, its CPU is heavily throttled.

Problem

I started receiving errors like:

write tcp 169.254.8.1:33834->10.1.0.2:14157: write: connection reset by peer

Where 10.1.0.2 is the database, that tells me that most likely the connection to the proxy was maintained but the connection to the host was killed. I would expect pq to be able to detect that, kill the connection and retry on a new one. But it seems it is not the case and the pool will happily continue using the connection even if it is effectively dead.

This is patchable with a SetConnMaxIdleTime or SetConnMaxLifetime, but I feel a network error like that should be able to detected and acted upon directly.

@Lekensteyn
Copy link

Possibly a duplicate of #835.

@Sytten
Copy link
Author

Sytten commented Feb 22, 2021

Thanks for linking issues! @Lekensteyn
The answer to it is not super great though: move to pgx :/

@Lekensteyn
Copy link

Hey @Sytten, can you share which pq version you are running? Is the Postgres connection secured with TLS?

#1013 (>= v1.9.0) should have addressed error handling when sending commands over a closed connection.

@Sytten
Copy link
Author

Sytten commented Mar 17, 2021

For some reason I am using an old version (1.7.0), unsure why goland resolved to that (most likely I already had it downloaded). I will try with a more recent version, thanks a LOT for that.

@Sytten
Copy link
Author

Sytten commented Mar 31, 2021

I still have issue with the latest version, either driver: bad connection or read: connection reset by peer.

@Christian-health
Copy link

@Sytten Did switching your database driver to /jackc/pgx resolve the 'connection reset by peer' issue?
I am using lib/pq/, and the issue I am encountering is that when PostgreSQL stops and then starts, the 'connection reset by peer' problem occurs. The database connection pool still uses invalid old connections to access the PostgreSQL database for a period of time(The time is determined by SetConnMaxIdleTime or SetConnMaxLifetime.). It does not establish new connections even after encountering the 'connection reset by peer' error.

I look forward to your reply. Thank you very much.

@Sytten
Copy link
Author

Sytten commented Aug 21, 2024

I dont remember, probably. I dont use golang anymore.

@Sytten Sytten closed this as not planned Won't fix, can't repro, duplicate, stale Aug 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants