sqlx icon indicating copy to clipboard operation
sqlx copied to clipboard

Add the ability to enable TCP keepalive on Postgres client connections

Open psFried opened this issue 1 year ago • 2 comments

Is your feature request related to a problem? Please describe.

We've observed some issues where our application hangs, though it's not necessarily certain that TCP keepalive would have prevented them.

Describe the solution you'd like

We'd like to enable TCP keepalive on our postgres client connections.

Describe alternatives you've considered

I've seen #3060 , and would agree that application-level timeouts are certainly more robust. But TCP keepalive is still useful, even once application-level timeouts are more well supported. For example, an application that's executing long-running queries might be able to detect a broken connection much more quickly with keepalive than it would with an application-level timeout. While keepalive is quite broadly supported, as pointed out in #3060 it's not universally supported. So this would need to be an option. Adding something on PgConnectionOptions seems pretty doable, but a compile-time feature could also work.

psFried avatar Oct 02 '24 20:10 psFried

Adding something on PgConnectionOptions seems pretty doable

This is reasonable. I'd accept a PR for this.

abonander avatar Oct 02 '24 20:10 abonander

I have tried to add this feature to sqlx in PR #3559 . Humbly I request your review @abonander and I'm willing to make changes to it.

xuehaonan27 avatar Oct 12 '24 06:10 xuehaonan27