Skip to content

Use the Windows defaults for unset keepalive time or interval - #698

Closed
forzen-dev wants to merge 1 commit into
rust-lang:masterfrom
forzen-dev:windows-keepalive-defaults
Closed

forzen-dev wants to merge 1 commit into
rust-lang:masterfrom
forzen-dev:windows-keepalive-defaults

Conversation

@forzen-dev

Copy link
Copy Markdown

On Windows, set_tcp_keepalive fills SIO_KEEPALIVE_VALS, which always sets both the keep-alive timeout and the interval. A field the TcpKeepalive leaves unset was written as 0:

  • TcpKeepalive::new().with_time(t) set a 0 ms interval. Once the connection had been idle for t, all the probes went out back to back, so a network stall of even a second at that moment dropped the connection.
  • TcpKeepalive::new().with_interval(i) set a 0 ms timeout.

On Unix each value is its own socket option, so an unset one keeps the system default. That makes with_time alone a reasonable thing to write, and libraries do: the mysql crate calls only with_time on Windows. We saw this in a database client. With with_time(10 s) on Windows 11, a MySQL connection whose server stopped answering was declared dead 10 s after its last traffic, where macOS took 25 s with the same settings.

This PR uses the defaults documented for SIO_KEEPALIVE_VALS (timeout 2 hours, interval 1 second) for whichever field is unset, and notes it in the with_time / with_interval docs. A new Windows unit test checks the struct built from each combination.

Tested on Windows 11 x64: cargo test --lib keepalive (with and without --features all) and cargo test --features all --test socket keepalive pass. cargo check --target x86_64-pc-windows-msvc --features all is clean. The clippy findings on that target are the same as on master and none are in this change.

SIO_KEEPALIVE_VALS always sets both the keep-alive timeout and the
interval. A TcpKeepalive with only one of them set wrote 0 for the other:
with_time alone set a 0 ms interval, so once the connection was idle every
probe went out back to back and a momentary network stall dropped it;
with_interval alone set a 0 ms timeout. Use the documented Windows
defaults (2 hours, 1 second) for the unset field instead.
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.

2 participants