Skip to content

Conversation

@sargarass
Copy link

@sargarass sargarass commented Feb 10, 2026

Does your PR solve an issue?

Situations where a server disconnects abruptly without sending a FIN packet

Is this a breaking change?

Yes

  Added                                                                                                                                                                                    
  - feat(postgres): TCP keepalive support — PostgreSQL connections now support TCP keepalive probes, matching libpq behavior. Keepalive is enabled by default (keepalives=1), consistent with libpq.

  - New PgConnectOptions methods:
    - keepalives(bool) / get_keepalives() — enable or disable TCP keepalives
    - keepalives_idle(Duration) / get_keepalives_idle() — idle time before probes begin
    - keepalives_interval(Duration) / get_keepalives_interval() — interval between probes
    - keepalives_retries(u32) / get_keepalives_retries() — max failed probes before dropping (Unix only)

  Changed
  - sqlx-core::net::connect_tcp now accepts an optional &KeepaliveConfig parameter to configure keepalive on the underlying TCP socket.
  - New dependency: socket2 0.5 (optional, enabled with _rt-tokio or _rt-async-std features) for cross-platform TCP keepalive configuration.

  Notes
  - MySQL connections pass None for keepalive (no keepalive configuration support yet).
  - Unix domain socket connections are unaffected — keepalive settings are ignored for UDS.
  - Zero values for timer parameters (keepalives_idle=0, keepalives_interval=0) are treated as "use OS default" and are not stored.

@sargarass
Copy link
Author

Decided not to revive the existing PR and to just create a new one. For now my company have to use fork since we faced the same issue as acheung-harmonicinc described here

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

Successfully merging this pull request may close these issues.

1 participant