Fix/bind addr ipv6 fallback#219
Open
pinguinfuss wants to merge 2 commits into
Open
Conversation
Commit 84a119f switched --bind-addr to "[::]:8443" for dual-stack, but binding fails with EAFNOSUPPORT when IPv6 is disabled in the kernel, leaving code-server unreachable. Detect IPv6 via /proc/net/if_inet6 and fall back to 0.0.0.0:8443 when it is unavailable.
There was a problem hiding this comment.
Thanks for opening this pull request! Be sure to follow the pull request template!
Author
|
Relates to #218 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description:
Commit 84a119f (#216) switched
--bind-addrto"[::]:8443"so the service listens on both IPv4 and IPv6 via dual-stack. This works fine when an IPv6 stack is present (even on IPv4-only networks), but it fails outright when IPv6 is disabled at the kernel level (e.g.ipv6.disable=1, kernel built withoutCONFIG_IPV6, or the module not loaded). In that case there is noAF_INET6socket family, so binding to[::]fails withEAFNOSUPPORTand code-server never starts — the container becomes unreachable.This PR detects IPv6 availability at startup via the presence of
/proc/net/if_inet6(the standard indicator that the kernel has IPv6 support) and chooses the bind address accordingly:[::]:8443(dual-stack, unchanged behaviour from listen on both ipv4 and ipv6 even when running container as root #216)0.0.0.0:8443(IPv4 fallback)Both the root and non-root exec paths use the shared
BIND_ADDRvariable.Benefits of this PR and context:
Restores the ability to run the container on hosts/kernels with IPv6 disabled, which regressed after #216, while fully preserving the dual-stack behaviour that #216 introduced for everyone else. No configuration or environment variables are required — the correct address is selected automatically.
How Has This Been Tested?
Verified in a container inheriting a host kernel with IPv6 fully disabled
(
/proc/net/if_inet6and/proc/sys/net/ipv6absent):[::]:8443fails with[Errno 97] Address family not supported by protocol(reproduces the regression).0.0.0.0:8443succeeds.[[ -e /proc/net/if_inet6 ]]correctly evaluates false, so the script selects the0.0.0.0fallback.On a normal dual-stack host
/proc/net/if_inet6is present and the script keeps[::]:8443, so existing IPv4+IPv6 behaviour is unchanged.Source / References:
--bind-addr "[::]:8443")(only IPv6-less networks with the stack still present).
Container does not work on host with ipv6 disabled docker-swag#92