launchbadge / sqlx

🧰 The Rust SQL Toolkit. An async, pure Rust SQL crate featuring compile-time checked queries without a DSL. Supports PostgreSQL, MySQL, and SQLite.
Apache License 2.0
13.52k stars 1.28k forks source link

feat: add TCP keepalive for MySQL and PostgresSQL. #3559

Open xuehaonan27 opened 1 month ago

xuehaonan27 commented 1 month ago

BREAK CHANGE: [sqlx_core::net::socket::connect_tcp]. New parameter added.

Add TCP keepalive configuration which could be enabled by [PgConnectOptions::tcp_keep_alive] and [MySqlConnectOptions::tcp_keep_alive].

Does your PR solve an issue?

fixes #3540

xuehaonan27 commented 1 month ago

Should I re-export TcpKeepalive in socket2 or give a definition on our own?

abonander commented 1 month ago

After some thought, I'm not entirely sure how much value this actually has.

As I worked out in https://github.com/estuary/flow/issues/1676#issuecomment-2392077544, keepalive likely won't solve the original reporter's problem.

It could be useful for other reasons, such as keeping connections from timing out, or catching when a server disconnected abruptly without sending a FIN packet.

However, because the connection state is managed directly, we won't see a keepalive timeout until the next time we try to read from or write to the socket, at which point we're already trying to use it anyway.

I suppose that's still preferable to it hanging forever on a read that will never complete, though.