-
-
Notifications
You must be signed in to change notification settings - Fork 925
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UDPSocket fails to bind to an IPv6 address unless AF_INET6 is explicitly set #5112
Comments
Well isn't that quirky. Our UDP logic is just a thin layer over the JDK APIs, so it may be the JDK's issue. I'll poke around a bit. |
Ok it turns out that we have roughly the correct behavior, because CRuby also raises an error in this case:
The remaining problem is that we don't raise the right error, so I'll fix that. |
The actual logic in JDK that appears to raise this error looks something like this: var5 = Net.checkAddress(var1);
if (this.family == StandardProtocolFamily.INET) {
InetAddress var6 = var5.getAddress();
if (!(var6 instanceof Inet4Address)) {
throw new UnsupportedAddressTypeException();
}
} So if I understand, it bails out if the default bind address is not an IPv6 address. That is a bit different sequence of events than CRuby, where it errors because getaddrinfo (to get the bits needed for the bind call) rejects the address as not being IPv6 (or something along those lines). I will fix our logic to throw a SocketError, so that will match. The error message for all causes of the JDK |
🤦♂️ I didn't expect this to be an actual expected behaviour. so weird. Thanks for checking it out. Having the same exception in jruby/mri would be nice, but from a developer POV the pattern for UDP will always be:
|
I've fixed the error so it's at least of the right type. I opted to make a new message since this is raised in a slightly different way than the error produced within CRuby's logic. I doubt it will matter. @jsvd Could you add a spec for this behavior to https://github.com/ruby/spec? That will ensure we don't regress. If you have any objection to the CRuby behavior, I recommend you open an issue with them at https://bugs.ruby-lang.org. |
Just for reference, the issue on cruby is https://redmine.ruby-lang.org/issues/5525
good idea 👍 |
This code path used to break for IPv6 addresses with `SocketError (getaddrinfo: Address family for hostname not supported)` because it was using `Socket::AF_INET` for every input. This is related to a JRuby bug[1] that is marked as `wontfix`. With the new implementation the address family is being retrieved by `Socket.getaddrinfo` and supports both IPv4 and IPv6 addresses. [1]: jruby/jruby#5112
This code path used to break for IPv6 addresses with `SocketError (getaddrinfo: Address family for hostname not supported)` because it was using `Socket::AF_INET` for every input. This is related to a JRuby bug[1] that is marked as `wontfix`. With the new implementation the address family is being retrieved by `Socket.getaddrinfo` and supports both IPv4 and IPv6 addresses. [1]: jruby/jruby#5112
This fix is related to a known JRuby bug[1] for UDPSocket initialization. `statsd-ruby v1.5.0` handles this issue correctly and is compatible with the `logstash-statsd-output` plugin [1]: jruby/jruby#5112
Binding to an UDP socket on an IPv6 address will fail unless an explicit AF_INET6 setting is passed to constructor. This is not required for TCP, only UDP:
Test script:
Results in:
The text was updated successfully, but these errors were encountered: