Decide whether Ninlil listeners claim their port exclusively on Windows, where another socket can share it #403

Closed
opened 2026-11-12 21:08:18 -05:00 by claude · 3 comments
Owner

A design question that came out of #397. No change is made until the owner decides.

What Windows does

  • Measured on lofnheim (Windows, .NET sockets): a dual-stack TCP listener on [::]:P and a separate socket on 127.0.0.1:P can both bind the same port. An IPv4 client that connects to 127.0.0.1:P then reaches the specific-address socket, not the wildcard listener. Linux refuses the second bind.
  • With Socket.ExclusiveAddressUse = true on the listener, the shared bind fails in either order. Rebinding an exclusive listener right after a close worked on loopback for TCP (with connections established and in TIME_WAIT) and for UDP.
  • More measurements from the #397 work are to be added here as a comment.

The trade-off

  • Today (no exclusive use): Ninlil's listener comes up and silently does not see the clients of an address another program holds on the same port.
  • With exclusive use on Windows: such a bind fails and is reported (FailedAddresses, an error in the log, /status). For an explicit list of listen addresses only that address fails. For the default configuration (one dual-stack wildcard socket) the whole transport is down.
  • How common the conflict is on port 53 is not established. On lofnheim, which has Hyper-V and WSL, svchost (the connection sharing service is running) holds UDP 0.0.0.0:53, and the virtual switch has the address 172.17.96.1. Nothing listens on TCP 53 there. Whether Ninlil's default UDP bind on port 53 succeeds beside that socket today, and which of the two then receives queries, has not been tested.

To decide

  1. Should Ninlil's listeners claim their port exclusively on Windows?
  2. If yes: for the default configuration, should a conflict take the transport down (loud), or should Ninlil fall back to binding each local address on its own and report the one that fails?
  3. Either way: README's Windows section and the transport-failure section should say how to find the program that holds a port (netstat -ano | findstr :53) and what Hyper-V, WSL and connection sharing do with port 53.

First step

  • On lofnheim: start Ninlil with the default configuration on port 53 beside the system's socket and record what binds, what answers a query to each local address, and what /status shows, with and without exclusive use.
A design question that came out of #397. No change is made until the owner decides. **What Windows does** - Measured on lofnheim (Windows, .NET sockets): a dual-stack TCP listener on `[::]:P` and a separate socket on `127.0.0.1:P` can both bind the same port. An IPv4 client that connects to `127.0.0.1:P` then reaches the specific-address socket, not the wildcard listener. Linux refuses the second bind. - With `Socket.ExclusiveAddressUse = true` on the listener, the shared bind fails in either order. Rebinding an exclusive listener right after a close worked on loopback for TCP (with connections established and in TIME_WAIT) and for UDP. - More measurements from the #397 work are to be added here as a comment. **The trade-off** - Today (no exclusive use): Ninlil's listener comes up and silently does not see the clients of an address another program holds on the same port. - With exclusive use on Windows: such a bind fails and is reported (`FailedAddresses`, an error in the log, `/status`). For an explicit list of listen addresses only that address fails. For the default configuration (one dual-stack wildcard socket) the whole transport is down. - How common the conflict is on port 53 is not established. On lofnheim, which has Hyper-V and WSL, `svchost` (the connection sharing service is running) holds UDP `0.0.0.0:53`, and the virtual switch has the address 172.17.96.1. Nothing listens on TCP 53 there. Whether Ninlil's default UDP bind on port 53 succeeds beside that socket today, and which of the two then receives queries, has not been tested. **To decide** 1. Should Ninlil's listeners claim their port exclusively on Windows? 2. If yes: for the default configuration, should a conflict take the transport down (loud), or should Ninlil fall back to binding each local address on its own and report the one that fails? 3. Either way: README's Windows section and the transport-failure section should say how to find the program that holds a port (`netstat -ano | findstr :53`) and what Hyper-V, WSL and connection sharing do with port 53. **First step** - On lofnheim: start Ninlil with the default configuration on port 53 beside the system's socket and record what binds, what answers a query to each local address, and what `/status` shows, with and without exclusive use.
Author
Owner

Measurements from the #397 work, taken on lofnheim (Windows, .NET sockets, TCP unless noted). They describe how a wildcard dual-stack socket and a specific-address socket behave on one port.

Without exclusive use

  • Wildcard first: a dual-stack [::]:P listener (IPv6Only off) is up, then a plain IPv4 socket binds 127.0.0.1:P. The bind is allowed and listens. An IPv4 client connecting to 127.0.0.1:P is queued on the specific socket, not the dual-stack one.
  • Specific first: a plain 127.0.0.1:P listener is up, then a dual-stack [::]:P bind. The bind is allowed. Clients of 127.0.0.1 still go to the specific socket.

With ExclusiveAddressUse = true on the dual-stack socket

  • Specific socket first: the dual-stack bind is refused ("Only one usage of each socket address..."). Setting IPv6Only before or after ExclusiveAddressUse makes no difference.
  • Exclusive dual-stack socket first, then a plain 127.0.0.1 bind: refused ("forbidden by its access permissions").
  • Rebinding exclusively on the same port after connections had closed (server closed first, TIME_WAIT) worked on loopback. A restart with remote connections in TIME_WAIT is untested.

Other observations

  • Port-0 binds: 3000 127.0.0.1 port-0 binds while a dual-stack listener held port P never landed on P, so only explicit-port binds collide.
  • The OS socket list (IPGlobalProperties.GetActiveTcpListeners / GetActiveUdpListeners) shows one dual-stack socket as two wildcard entries, 0.0.0.0:P and [::]:P, for TCP and UDP alike. A specific-address socket adds its own entry. Linux lists one [::] entry.
  • Port-0 numbering: TCP and UDP use separate sequential counters over 49152 to 65535, so a UDP port-0 number can equal a port another program holds on a specific address for TCP only.
  • On lofnheim itself (Hyper-V and WSL installed): svchost holds UDP 0.0.0.0:53 (SharedAccess and hns running), vEthernet (Default Switch) is 172.17.96.1, nothing listens on TCP 53. Not yet tested: what Ninlil's default bind on port 53 does beside that socket.

Trade-off
Exclusive use turns a silent loss of clients into a failed bind. With the default single dual-stack socket, the whole transport is then lost whenever another program holds the same port on one specific address.

Options to weigh

  1. Bind a wildcard-IPv4 and a wildcard-IPv6 socket separately, each exclusive.
  2. Fall back to explicit addresses when the exclusive wildcard bind is refused.
  3. Accept sharing and log it. The check the #397 test uses (every entry on the port is a wildcard address and none appears twice) can serve as the detection.

#397 itself is fixed in the test only and changes no product behaviour.

Measurements from the #397 work, taken on lofnheim (Windows, .NET sockets, TCP unless noted). They describe how a wildcard dual-stack socket and a specific-address socket behave on one port. **Without exclusive use** - Wildcard first: a dual-stack `[::]:P` listener (IPv6Only off) is up, then a plain IPv4 socket binds `127.0.0.1:P`. The bind is allowed and listens. An IPv4 client connecting to `127.0.0.1:P` is queued on the specific socket, not the dual-stack one. - Specific first: a plain `127.0.0.1:P` listener is up, then a dual-stack `[::]:P` bind. The bind is allowed. Clients of `127.0.0.1` still go to the specific socket. **With `ExclusiveAddressUse = true` on the dual-stack socket** - Specific socket first: the dual-stack bind is refused ("Only one usage of each socket address..."). Setting `IPv6Only` before or after `ExclusiveAddressUse` makes no difference. - Exclusive dual-stack socket first, then a plain `127.0.0.1` bind: refused ("forbidden by its access permissions"). - Rebinding exclusively on the same port after connections had closed (server closed first, TIME_WAIT) worked on loopback. A restart with remote connections in TIME_WAIT is untested. **Other observations** - Port-0 binds: 3000 `127.0.0.1` port-0 binds while a dual-stack listener held port P never landed on P, so only explicit-port binds collide. - The OS socket list (`IPGlobalProperties.GetActiveTcpListeners` / `GetActiveUdpListeners`) shows one dual-stack socket as two wildcard entries, `0.0.0.0:P` and `[::]:P`, for TCP and UDP alike. A specific-address socket adds its own entry. Linux lists one `[::]` entry. - Port-0 numbering: TCP and UDP use separate sequential counters over 49152 to 65535, so a UDP port-0 number can equal a port another program holds on a specific address for TCP only. - On lofnheim itself (Hyper-V and WSL installed): svchost holds UDP `0.0.0.0:53` (SharedAccess and hns running), vEthernet (Default Switch) is 172.17.96.1, nothing listens on TCP 53. Not yet tested: what Ninlil's default bind on port 53 does beside that socket. **Trade-off** Exclusive use turns a silent loss of clients into a failed bind. With the default single dual-stack socket, the whole transport is then lost whenever another program holds the same port on one specific address. **Options to weigh** 1. Bind a wildcard-IPv4 and a wildcard-IPv6 socket separately, each exclusive. 2. Fall back to explicit addresses when the exclusive wildcard bind is refused. 3. Accept sharing and log it. The check the #397 test uses (every entry on the port is a wildcard address and none appears twice) can serve as the detection. #397 itself is fixed in the test only and changes no product behaviour.
Author
Owner

Owner decision, 2026-11-13: yes. Ninlil's listeners claim their port exclusively on Windows, so that no other socket can share it.

This issue is now the implementation task for that decision. The measurements in the comment above show which socket combinations Windows allows today; the work is to set exclusive address use on every listener socket Ninlil binds on Windows and to prove with a test on the Windows runner that a second bind fails.

Owner decision, 2026-11-13: yes. Ninlil's listeners claim their port exclusively on Windows, so that no other socket can share it. This issue is now the implementation task for that decision. The measurements in the comment above show which socket combinations Windows allows today; the work is to set exclusive address use on every listener socket Ninlil binds on Windows and to prove with a test on the Windows runner that a second bind fails.
Author
Owner

Owner decision, 2026-11-13, on what happens when the exclusive wildcard bind fails on Windows: fall back to one exclusive bind per local address.

Why it came up: on a Windows machine where another program already holds UDP 53 on the wildcard address (measured on the Windows runner: svchost for connection sharing, Hyper-V and WSL holds 0.0.0.0:53), an exclusive wildcard bind of UDP 53 fails, while a shared one succeeds today. Exclusive binds on 127.0.0.1:53 and ::1:53 succeed beside that socket. Without a fallback, DNS over UDP would stop starting on such a machine with the default configuration.

Owner decision, 2026-11-13, on what happens when the exclusive wildcard bind fails on Windows: fall back to one exclusive bind per local address. Why it came up: on a Windows machine where another program already holds UDP 53 on the wildcard address (measured on the Windows runner: `svchost` for connection sharing, Hyper-V and WSL holds `0.0.0.0:53`), an exclusive wildcard bind of UDP 53 fails, while a shared one succeeds today. Exclusive binds on `127.0.0.1:53` and `::1:53` succeed beside that socket. Without a fallback, DNS over UDP would stop starting on such a machine with the default configuration.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
lantea-one/ninlil#403
No description provided.