Skip to content

Allow TCP listeners to restart on Unix - #545

Merged
lukewilliamboswell merged 1 commit into
mainfrom
fix/tcp-listener-restart
Nov 11, 2026
Merged

lukewilliamboswell merged 1 commit into
mainfrom
fix/tcp-listener-restart

Conversation

@lukewilliamboswell

@lukewilliamboswell lukewilliamboswell commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Set SO_REUSEADDR before binding Unix TCP listeners so a restarted server can bind while connections from the previous run are still in TIME_WAIT. Keep SO_EXCLUSIVEADDRUSE on Windows.

The regression test drives a loopback connection through a server-initiated close, then immediately binds the same address and port again. The existing test verifies that a second live listener still returns AddrInUse.

Closes #544.

Verification

  • The new test reproduced AddrInUse before the fix and passed after it.
  • cargo fmt --all -- --check
  • cargo clippy --locked --all-targets -- -D warnings
  • cargo test --locked --all-targets passed all 200 tests on Linux.
  • ROC=/path/to/nightly-2026-11-06-34f137a/roc python3 scripts/test.py passed the full native Linux suite.
  • A separate two-process Roc reproduction observed the first server's connection in TIME_WAIT via /proc/net/tcp, then immediately rebound the same port and served another connection.

@lukewilliamboswell
lukewilliamboswell merged commit f2fb7f3 into main Nov 11, 2026
32 checks passed
@lukewilliamboswell
lukewilliamboswell deleted the fix/tcp-listener-restart branch November 11, 2026 02:15
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.

Tcp.listen! fails with AddrInUse when a server is restarted on the same port (no SO_REUSEADDR on Unix)

1 participant