Skip to content
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

Socket.getaddrinfo returns wrong data when IPv6 is disabled and running on Java8 #4479

Closed
nbarrientos opened this issue Feb 7, 2017 · 7 comments

Comments

@nbarrientos
Copy link
Contributor

Common environment for all tests:

# cat /etc/redhat-release 
CentOS Linux release 7.3.1611 (Core) 
# uname -a
Linux foo.cern.ch 3.10.0-514.6.1.el7.x86_64 #1 SMP Wed Jan 18 13:06:36 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

The issue is the following:

[root@nbj8 ~]# grep v6 /etc/sysctl.conf 
net.ipv6.conf.all.disable_ipv6 = 1
[root@nbj8 ~]# export PATH=/root/jruby-1.7.26/bin/:$PATH
[root@nbj8 ~]# jruby -v
jruby 1.7.26 (1.9.3p551) 2016-08-26 69763b8 on OpenJDK 64-Bit Server VM 1.8.0_121-b13 +jit [linux-amd64]
[root@nbj8 ~]# java -version
openjdk version "1.8.0_121"
OpenJDK Runtime Environment (build 1.8.0_121-b13)
OpenJDK 64-Bit Server VM (build 25.121-b13, mixed mode)
[root@nbj8 ~]# jruby -rsocket -e 'puts Socket.getaddrinfo("xldaplb12.cern.ch", nil, :INET)'
AF_INET
0
188.184.36.140
188.184.36.140
2
1
6
AF_INET
0
18.127.0.0
18.127.0.0
2
1
6
[root@nbj8 ~]# whois 18.127.0.0
...
OriginAS:       AS3
Organization:   Massachusetts Institute of Technology (MIT-2)
RegDate:        1994-01-01
Updated:        2010-09-28

In other words, when IPv6 is totally disabled and jRuby is running on top of Java8, Socket.getaddrinfo returns addresses that don't belong to the name being queried. The behaviour is the same when trying to reproduce the problem with jRuby 9k:

[root@nbj8 ~]# export PATH=/root/jruby-9.1.7.0/bin/:$PATH
[root@nbj8 ~]# jruby -v
jruby 9.1.7.0 (2.3.1) 2017-01-11 68056ae OpenJDK 64-Bit Server VM 25.121-b13 on 1.8.0_121-b13 +jit [linux-x86_64]
[root@nbj8 ~]# jruby -rsocket -e 'puts Socket.getaddrinfo("xldaplb12.cern.ch", nil, :INET)'
AF_INET
0
188.184.36.140
188.184.36.140
2
1
6
AF_INET
0
151.127.0.0
151.127.0.0
2
1
6
[root@nbj8 ~]# java -version
openjdk version "1.8.0_121"
OpenJDK Runtime Environment (build 1.8.0_121-b13)
OpenJDK 64-Bit Server VM (build 25.121-b13, mixed mode)
[root@nbj8 ~]# whois 151.127.0.0
inetnum:        151.127.0.0 - 151.127.63.255
netname:        OVH-DSL
org:            ORG-OT26-RIPE
descr:          DSL static IP
descr:          www.ovh.com

I have no idea where 151.127.0.0 nor 18.127.0.0 are coming from, but all the wrong addresses that I've seen have the last two bytes zeroed as common denominator.

It works fine regardless of the Java version though when IPv6 is not disabled:

[root@nbj7 ~]# export PATH=/root/jruby-1.7.26/bin/:$PATH
[root@nbj7 ~]# java -version
java version "1.7.0_121"
OpenJDK Runtime Environment (rhel-2.6.8.0.el7_3-x86_64 u121-b00)
OpenJDK 64-Bit Server VM (build 24.121-b00, mixed mode)
[root@nbj7 ~]# jruby -rsocket -e 'puts Socket.getaddrinfo("xldaplb12.cern.ch", nil, :INET)'
AF_INET
0
188.184.36.140
188.184.36.140
2
1
6
AF_INET6
0
2001:1458:201:6f:0:0:100:c
2001:1458:201:6f:0:0:100:c
10
1
6
[root@nbj8 ~]# export PATH=/root/jruby-1.7.26/bin/:$PATH
[root@nbj8 ~]# java -version
openjdk version "1.8.0_121"
OpenJDK Runtime Environment (build 1.8.0_121-b13)
OpenJDK 64-Bit Server VM (build 25.121-b13, mixed mode)
[root@nbj8 ~]# jruby -rsocket -e 'puts Socket.getaddrinfo("xldaplb12.cern.ch", nil, :INET)'
AF_INET
0
188.184.36.140
188.184.36.140
2
1
6
AF_INET6
0
2001:1458:201:6f:0:0:100:c
2001:1458:201:6f:0:0:100:c
10
1
6

We're happy to provide more information if needed.

Thanks for looking into it!

@headius
Copy link
Member

headius commented Feb 9, 2017

It's possible this is a JDK bug.

getaddrinfo on both 1.7 and 9k simply uses Java networking APIs to get a list of addresses. If these addresses contain bogus information, it wouldn't be our fault. Alternatively, if they contain this information but with some indicator that it's not relevant (like tagged as IPv6 or something) we may need to filter it.

Can you see what Java returns for a list of addresses?

@nbarrientos
Copy link
Contributor Author

nbarrientos commented Feb 19, 2017

Indeed 😢

# grep disable_ /etc/sysctl.conf
net.ipv6.conf.all.disable_ipv6 = 1
# java -version
openjdk version "1.8.0_121"
OpenJDK Runtime Environment (build 1.8.0_121-b13)
OpenJDK 64-Bit Server VM (build 25.121-b13, mixed mode)
# host xldaplb12.cern.ch
xldaplb12.cern.ch has address 188.184.36.140
xldaplb12.cern.ch has IPv6 address 2001:1458:201:6f::100:c
# cat ResolvName.java
import java.net.InetAddress;
import java.net.UnknownHostException;

public class ResolvName {

    public static void main(String[] args) {
	try {
		for(InetAddress addr : InetAddress.getAllByName("xldaplb12.cern.ch"))
    			System.out.println(addr.getHostAddress());
	} catch(UnknownHostException e) {
    			System.out.println(e);
        }
		
    }

}
# javac ResolvName.java 
# java ResolvName
188.184.36.140
5.127.0.0
# java ResolvName
188.184.36.140
155.127.0.0
# jruby -rsocket -e 'puts Socket.getaddrinfo("xldaplb12.cern.ch", nil, :INET)'
AF_INET
0
188.184.36.140
188.184.36.140
2
1
6
AF_INET
0
71.127.0.0
71.127.0.0
2
1
6

@nbarrientos
Copy link
Contributor Author

Java7 seems to do something sensible:

# grep disable_ /etc/sysctl.conf
net.ipv6.conf.all.disable_ipv6 = 1
# java -version
java version "1.7.0_131"
OpenJDK Runtime Environment (rhel-2.6.9.0.el7_3-x86_64 u131-b00)
OpenJDK 64-Bit Server VM (build 24.131-b00, mixed mode)
# javac ResolvName.java 
# host xldaplb12.cern.ch
xldaplb12.cern.ch has address 188.184.36.140
xldaplb12.cern.ch has IPv6 address 2001:1458:201:6f::100:c
# java ResolvName
188.184.36.140
# java ResolvName
188.184.36.140

@nbarrientos
Copy link
Contributor Author

nbarrientos commented Feb 19, 2017

Btw, we have IPv6 disabled over here because of #3663. Could the issue please be reopened and the patch looked at?

@nbarrientos
Copy link
Contributor Author

I got some extra eyes over here on the issue, we'll keep you posted.

@nbarrientos
Copy link
Contributor Author

This ticket can be closed, the issue seems to be directly related to Java8 and nscd:

# java -version
openjdk version "1.8.0_121"
OpenJDK Runtime Environment (build 1.8.0_121-b13)
OpenJDK 64-Bit Server VM (build 25.121-b13, mixed mode)
# systemctl status nscd | grep Active
   Active: active (running) since Tue 2017-02-21 10:18:05 CET; 3s ago
# nscd -i hosts
# java ResolvName
188.184.36.140
220.127.0.0
# java ResolvName
188.184.36.140
235.127.0.0
# systemctl stop nscd
Warning: Stopping nscd.service, but it can still be activated by:
  nscd.socket
# systemctl status nscd | grep Active
   Active: inactive (dead) since Tue 2017-02-21 10:18:20 CET; 1s ago
# java ResolvName
188.184.36.140
# java ResolvName
188.184.36.140

@enebo enebo added this to the Invalid or Duplicate milestone Feb 21, 2017
@enebo enebo closed this as completed May 16, 2017
@nbarrientos
Copy link
Contributor Author

JFTR, this was the bug: https://bugzilla.redhat.com/show_bug.cgi?id=1324568

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants