Skip to content

Bind-only ports and support for so_reuseport_aware on Windows - #80

Merged
darkrift merged 1 commit into
hermeticbuild:masterfrom
darkrift:so_reuseport_windows
Aug 7, 2026
Merged

Bind-only ports and support for so_reuseport_aware on Windows#80
darkrift merged 1 commit into
hermeticbuild:masterfrom
darkrift:so_reuseport_windows

Conversation

@darkrift

@darkrift darkrift commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

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:

    • SO_REUSEPORT on Unix.
    • SO_REUSEADDR on Windows.
  • 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

  • bazel test //cmd/svcinit:svcinit_test
  • bazel test //so_reuseport:so_reuseport_test //so_reuseport:so_reuseport_js_test
  • Windows cross-build of //cmd/svcinit:svcinit
  • Windows cross-build of //go_service:go_service

@darkrift
darkrift force-pushed the so_reuseport_windows branch 4 times, most recently from 7fb4d54 to e758543 Compare August 6, 2026 16:24
@darkrift darkrift changed the title Windows so_reuseport works with SO_REUSEADDR Bind-only ports and support for so_reuseport_aware on Windows Aug 6, 2026
@darkrift
darkrift force-pushed the so_reuseport_windows branch 2 times, most recently from 9020d9b to 9630c88 Compare August 6, 2026 18:15
@darkrift
darkrift force-pushed the so_reuseport_windows branch from 9630c88 to 02f40b4 Compare August 6, 2026 22:49
@darkrift
darkrift marked this pull request as ready for review August 6, 2026 23:15

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread tests/go_service/main.go
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",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

@darkrift
darkrift merged commit 36101fc into hermeticbuild:master Aug 7, 2026
2 checks passed
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