Skip to content

Add keepalive, set_keepalive to TcpStream implementations#154025

Open
yungcomputerchair wants to merge 3 commits intorust-lang:mainfrom
yungcomputerchair:keepalive
Open

Add keepalive, set_keepalive to TcpStream implementations#154025
yungcomputerchair wants to merge 3 commits intorust-lang:mainfrom
yungcomputerchair:keepalive

Conversation

@yungcomputerchair
Copy link

@yungcomputerchair yungcomputerchair commented Mar 18, 2026

What

The current implementation of TcpStream does not expose SO_KEEPALIVE: #69774

Why

It seems the reason this has not yet been implemented is because the initial implementation went as far as to take the keepalive interval as a parameter. However, Windows does not directly expose these intervals for reading, causing there to be some debate about the shape of the API (see the discussion of this here).

How

I am proposing that this API is enabled with a bool parameter to align with the implementation in both Windows and Unix. With regards to the call to setsockopt, Windows expects a disable/enable, and Unix does as well.

The extra configuration for Unix that allows the interval to be tweaked could be done through an additional API perhaps, but I don't think that's stopping us from exposing the switch to at least enable the behavior with the OS defaults.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Mar 18, 2026
@rustbot
Copy link
Collaborator

rustbot commented Mar 18, 2026

r? @joboet

rustbot has assigned @joboet.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @ChrisDenton, libs
  • @ChrisDenton, libs expanded to 8 candidates
  • Random selection from Mark-Simulacrum, joboet

@yungcomputerchair
Copy link
Author

As a new contributor, there were a few things I wasn't sure about:

  • I don't think there is a "tracking issue" for this feature, just the one I linked above with the discussion. I am guessing a tracking issue will need to be created for this, and the issue number in the code will need to be updated.
  • I don't know if unstable features are defined somewhere, so I just made sure the name was unique and matched for both new APIs.
  • For motor, the lib does not expose a keepalive setting (according to the docs), so I went with unsupported()
  • For SOLID and Hermit, I believe the implementation was straightforward, but I'm not sure how to test. Is there a CI flow I can use?
  • Is there anything else I need to do to validate or properly propose this change?

Thanks :)

@rust-log-analyzer

This comment has been minimized.

@rustbot rustbot added the O-windows Operating system: Windows label Mar 18, 2026
@rust-log-analyzer

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

O-windows Operating system: Windows S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants