Skip to content

net: hold a forward test's port on the wildcard address, so macOS binds the forward - #796

Merged
techomancer merged 1 commit into
techomancer:mainfrom
steigr:fix/net-held-port-macos
Nov 20, 2026
Merged

techomancer merged 1 commit into
techomancer:mainfrom
steigr:fix/net-held-port-macos

Conversation

@steigr

@steigr steigr commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

On macOS, five port-forward tests fail every run with "the forward never listened":

  • dev::{bcm5701,daynaport,ioc3::eth,seeq8003}::tests::a_restart_keeps_the_port_forwards
  • dev::mec::tests::a_dropped_mec_frees_its_port_forwards

Link::forward_on_a_held_port held 127.0.0.1:P with SO_REUSEADDR, without listening, and the NAT forward then bound the same 127.0.0.1:P with TcpListener::bind, which sets SO_REUSEADDR only. Linux allows this while the hold isn't listening. macOS (like the BSDs) refuses a second bind of the identical address and port unless both sockets set SO_REUSEPORT, but does let a specific address share a port with a wildcard bind.

The helper now holds 0.0.0.0:P. A socket probe shows macOS and Linux both accept the forward's 127.0.0.1:P bind next to that hold, and neither handed the held port to any of 20,000 binds to port 0. So other tests still can't take the port. The forward listener is unchanged: adding SO_REUSEPORT there would let a second emulator bind the same forward port.

Also adds a short note in clanker/net/ and its entry in clanker/INDEX.md.

Tested on macOS: the five tests pass, and cargo test --lib -- --skip dev::kona::back::tiles reports 4865 passed, 0 failed. Linux was checked only with the socket probe, not by running cargo tests.

🤖 Generated with Claude Code

…ds the forward

Link::forward_on_a_held_port held 127.0.0.1:P with SO_REUSEADDR and the
NAT forward then bound 127.0.0.1:P. Linux allows that while the hold is
not listening; macOS refuses an identical second bind unless both
sockets set SO_REUSEPORT, so the five NIC restart/drop port-forward tests
failed there with "the forward never listened". Holding 0.0.0.0:P lets
the forward bind 127.0.0.1:P on both systems, and the kernel still hands
the held port to no other test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@steigr
steigr marked this pull request as ready for review November 20, 2026 15:06
@techomancer
techomancer merged commit 9d6c5d9 into techomancer:main Nov 20, 2026
14 of 15 checks passed
@techomancer

Copy link
Copy Markdown
Owner

join us on SGUG discord #emulation please. it would be nice to chat sometime.

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