Skip to content

connectd: set IPV6_V6ONLY=1 on IPv6 sockets for consistent dual-stack behaviour#9148

Open
nGoline wants to merge 2 commits into
ElementsProject:masterfrom
nGoline:ipv4-and-ipv6-fix
Open

connectd: set IPV6_V6ONLY=1 on IPv6 sockets for consistent dual-stack behaviour#9148
nGoline wants to merge 2 commits into
ElementsProject:masterfrom
nGoline:ipv4-and-ipv6-fix

Conversation

@nGoline

@nGoline nGoline commented May 19, 2026

Copy link
Copy Markdown
Collaborator

As discussed in #9013, systems with net.ipv6.bindv6only=0 (macOS, Fedora, Arch, vanilla kernels) create dual-stack sockets by default: binding '::' also covers '0.0.0.0', so the subsequent IPv4 wildcard bind fails with EADDRINUSE. Debian/Ubuntu ship bindv6only=1 so both binds succeed here, which is why this was never noticed on typical Linux CI.

On this PR I've gone with option 1 and 2: Explicitly set IPV6_V6ONLY=1 on AF_INET6 sockets before bind so both address families always get independent sockets regardless of the system sysctl. Also free the errstr allocation left behind when the IPv4 bind fails acceptably (IPv6 succeeded), fixing a memleak in connectd on those systems.

Also gave a better chance for test_ipv4_and_ipv6 in case something fails.

Changelog-Fixed: connectd: on macOS and other systems with dual-stack IPv6 default, wildcard '--addr=:' now correctly binds both IPv4 and IPv6.

Closes #9013


This PR also fixes the memleak in tests/test_connection.py::test_websocket and tests/test_connection.py::test_wss_proxy.

Closes #9016
Closes #9017

@nGoline nGoline self-assigned this May 19, 2026
@nGoline nGoline requested review from ddustin and rustyrussell May 19, 2026 13:48
@nGoline nGoline added this to the v26.09 milestone May 21, 2026
@nGoline nGoline removed the request for review from rustyrussell June 19, 2026 14:52
@nGoline nGoline added the Status::Ready for Review The work has been completed and is now awaiting evaluation or approval. label Jun 19, 2026
@nGoline nGoline force-pushed the ipv4-and-ipv6-fix branch 2 times, most recently from 237aa1e to ec72a26 Compare July 8, 2026 13:58
@nGoline nGoline requested a review from daywalker90 July 8, 2026 13:58
… behaviour

Systems with net.ipv6.bindv6only=0 (macOS, Fedora, Arch, vanilla kernels) create dual-stack sockets by default: binding '::' also covers '0.0.0.0', so the subsequent IPv4 wildcard bind fails with EADDRINUSE.  Debian/Ubuntu ship bindv6only=1 so both binds succeed here, which is why this was never noticed on typical Linux CI.

Explicitly set IPV6_V6ONLY=1 on AF_INET6 sockets before bind so both address families always get independent sockets regardless of the system sysctl.  Also free the errstr allocation left behind when the IPv4 bind fails acceptably (IPv6 succeeded), fixing a memleak in connectd on those systems.

test_ipv4_and_ipv6: accept IPv6-only binding in the single-socket case, which can still occur on IPv4-only hosts.

Changelog-Fixed: connectd: on macOS and other systems with dual-stack IPv6 default, wildcard '--addr=:<port>' now correctly binds both IPv4 and IPv6.
@daywalker90 daywalker90 force-pushed the ipv4-and-ipv6-fix branch 6 times, most recently from 20b7568 to 1f603e6 Compare July 10, 2026 16:02
remove the manual node start as it is covered by running pytests

Changelog-None
@daywalker90

Copy link
Copy Markdown
Collaborator

Since i don't have a machine with a macos kernel and it seems to not be an issue on all systems with

cat /proc/sys/net/ipv6/bindv6only
0

i have reworked the macos workflow to also run tests and added the 3 tests related to this PR to CI.

The fix makes sense and seems to be working

@nGoline nGoline added Status::Release Ready ✅🤩 and removed Status::Ready for Review The work has been completed and is now awaiting evaluation or approval. labels Jul 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pytest: **BROKEN** in test_wss_proxy pytest: **BROKEN** in test_websocket pytest: **BROKEN** Error in test test_ipv4_and_ipv6

2 participants