-
Notifications
You must be signed in to change notification settings - Fork 911
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
Add TcpKeepAlive #360
Comments
If you were using an actual postgres, you could configure keepalive from server side. That said, client-side keepalives don't sound like a bad idea. |
http://felixge.de/2014/08/26/tcp-keepalive-with-golang.html Looking at the options available to libpq and the above,
|
Yeah, I think you're right. I don't see any nice way of accessing the underlying file descriptor of a TCPConn, which is a great shame. I wonder if this is a case of nanny city or whether we could do something about this for Go 1.5. |
Is there a reason the If you guys are cool with switching to a |
Huh? What about this path? |
Yeah, that's a derp. Sorry. What about getting rid of the Dialer interface and defaultDialer, and using net.Dialer instead? That way the dial function can instantiate a net.Dialer and set the timeout, deadline, and keep alive on it, and then call |
That would break applications for no real reason.
I don't see why you couldn't just special-case the TCP path and set the keepalive parameters there. If people are using custom dialers, they should set said parameters themselves. |
Or we could do it for custom dialers as well if a type assertion to a *net.TCPConn holds. |
I don't think I understand how you can use custom dialers. I see that drv implements the driver.Driver interface. But I'm not sure how you can use a dialer other than But I think you're right, a special-case for TCP will work best. |
By registering your own driver and calling pq.DialOpen instead of implementing your own. |
+1 on this enhancement. When DB failover is occurring on Amazon RDS service, I'm seeing all my DB connection hanging indefinitely. I'll go with johto advice and implement my own driver, wrapping pq. |
I'm not sure this will actually help to be honest. IIRC once there's un-ACKed data in the pipe (i.e. you're actually doing a query and not just sitting idle), the keepalive intervals are ignored and much higher timeouts kick in. But I might as well be wrong. |
Thanks for pointing this out, will need to experiment for sure, good thing this is reasonably easy to reproduce. Other solution I'm thinking of would be to simply maintain max idle period for every connection by wrapping BTW I assume there's no heartbeating protocol in postgres, so idle connections effectively stay silent, is this correct? |
You probably figured this out already, but yes, idle connections are idle. |
Any update for this? |
Did anyone try cbandy's solution? |
I believe for most users Thus in the future we shouldn't see problems similar to the one originally discussed in this issue. |
Did you implement the driver and pg wrap? i want to learn how you implement and use it ?thank you very much. |
@kingcr7 since golang 1.6 my problem has been solved by setting max connection lifetime via sql package (https://golang.org/pkg/database/sql/#DB.SetConnMaxLifetime). Works like a charm, haven't had any issues with zombie connection for a few years now. |
Why cannot the keep alive change like this Clever#1 be merged in this library? |
lib/pq lacks support for keep alive lib/pq#360 Going with Clever/pq forked as practo/pq as Clever/pq lacks go module support
It would be great if you could try this #999 TCP keepalive solution on real workloads. Here is an example https://github.com/marselester/pg-keepalive. |
I think it is also worth pointing out that TCP keepalive alone won't help with the original issue, because:
see currently open Golang issue for details - golang/go#31490 |
lib/pq lacks support for keep alive lib/pq#360 Going with Clever/pq forked as practo/pq as Clever/pq lacks go module support
lib/pq lacks support for keep alive lib/pq#360 Going with Clever/pq forked as practo/pq as Clever/pq lacks go module support
lib/pq lacks support for keep alive lib/pq#360 Going with Clever/pq forked as practo/pq as Clever/pq lacks go module support
lib/pq lacks support for keep alive lib/pq#360 Going with Clever/pq forked as practo/pq as Clever/pq lacks go module support
lib/pq lacks support for keep alive lib/pq#360 Going with Clever/pq forked as practo/pq as Clever/pq lacks go module support
I'm using this package with amazon's redshift, and am using it to do some long running queries (max around 15 minutes). The problem is that sometimes the connection is lost during these queries and the client is never notified, so gets blocked waiting for a response. It'd be nice if there were support for TcpKeepAlive to keep these connections from timing out.
The text was updated successfully, but these errors were encountered: