Bind-only ports and support for so_reuseport_aware on Windows - #80
Conversation
7fb4d54 to
e758543
Compare
9020d9b to
9630c88
Compare
9630c88 to
02f40b4
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 02f40b4d05
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| soReuseport := flag.Bool("so-reuseport", false, "If true, sets SO_REUSEPORT when binding the address") | ||
| soReuseport := flag.Bool( | ||
| "so-reuseport", | ||
| os.Getenv("RULES_ITEST_ENABLE_SO_REUSEPORT") == "1", |
There was a problem hiding this comment.
Force the negative fixture to leave reuseport disabled
With this default, every itest_service marked so_reuseport_aware gets RULES_ITEST_ENABLE_SO_REUSEPORT=1 from the runner and this test binary now enables the reusable-port option automatically. That includes tests/so_reuseport:_no_reuseport_service, whose hygiene test is wrapped by must_fail to prove a service that does not set the option cannot bind; instead it starts successfully, so no_reuseport_service_hygiene_test fails under the checked CI workflow that runs bazel test //... from tests. Pass -so-reuseport=false for that fixture or otherwise opt it out of this env-based default.
Useful? React with 👍 / 👎.
Summary
Add Windows support for so_reuseport_aware and change reusable port reservations from listening sockets to bind-only sockets.
Motivation
On Windows, SO_REUSEADDR allows the service and reservation sockets to bind the same port, but it does not provide Unix-style SO_REUSEPORT connection distribution.
Because the reservation socket was also listening, health-check connections could be routed to it instead of the service. The reservation never accepted those connections, causing health checks to time out even though the service had started successfully.
Changes
Introduce platform-specific bind-only reusable port reservations:
Create Windows sockets with WSA_FLAG_NO_HANDLE_INHERIT.
Keep reservations open for the service manager’s lifetime without calling listen.
Preserve explicitly configured port values instead of always binding port 0.
Set RULES_ITEST_ENABLE_SO_REUSEPORT=1 only in the environment of services configured with so_reuseport_aware = True.
Update the test service to use that environment variable instead of an explicit command-line flag.
Add documentation for the environment variable and platform-specific socket behavior.
Add a regression test proving that connections reach the service listener while the bind-only reservation remains open.
Validation