Domain Name Resolution Not Working in Java Applications on Ubuntu64 9.04 MAChine. All Other Software Resolves Dns Correctly

Domain name resolution not working in Java Applications on Ubuntu64 9.04 machine. All other software resolves DNS correctly

Once again, thanks to the guidance of the people here, I've found an answer. The Java program above works when I do the following:

java -Djava.net.preferIPv4Stack=true DomainResolutionTest

Details:

jgreenwood@jeg-ubuntu64:~$ java -Djava.net.preferIPv4Stack=true DomainResolutionTest 
www.google.com/209.85.225.106
jgreenwood@jeg-ubuntu64:~$ java DomainResolutionTest ERROR: www.google.com
java.net.UnknownHostException: www.google.com
at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:849)
at java.net.InetAddress.getAddressFromNameService(InetAddress.java:1200)
at java.net.InetAddress.getAllByName0(InetAddress.java:1153)
at java.net.InetAddress.getAllByName(InetAddress.java:1083)
at java.net.InetAddress.getAllByName(InetAddress.java:1019)
at java.net.InetAddress.getByName(InetAddress.java:969)
at DomainResolutionTest.main(DomainResolutionTest.java:12)

It turns out that there is a bug in the IPv6 stack. There are a couple of posts that led me to this conclusion:

http://uclue.com/?xq=2127

http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=477211

https://answers.launchpad.net/ubuntu/+question/23024

I sure hope I don't have to add the IPv4 crap in every time I run a Java app. The final solution may be in the second link - a missing package. We shall see.

Debian Bug report logs - #477211
ia32-sun-java6-bin: Needs to depend on
lib32nss-mdns
...
Cannot resolve domain names. Resolve
fine on the rest of the system, have
not tested with other JDK's.
Installed from package and set with
update-java-alternatives.

DNS works for everything else on my
system. Running on Debian
2.6.23-AMD64. Have tried both Lenny packages and Sid packages. Works as
expected with sun-java6-bin, fails
with ia32-sun-java6-bin. Arg. ... If
you hit java with strace you'll see
that it is trying to use
libnss_mdns4_minimal.so.2, which is
available in the package
lib32nss-mdns. You should add a
dependency on that to fix the bug.

Same thing happens for sun-java6-bin -
libnss-mdns is used here.

The package is indeed missing on my machine:

jgreenwood@jeg-ubuntu64:~$ dpkg -L lib32nss-mdns
Package `lib32nss-mdns' is not installed.
Use dpkg --info (= dpkg-deb --info) to examine archive files,
and dpkg --contents (= dpkg-deb --contents) to list their contents.

Either way, I hope this post helps someone else, because this was a major PITA to figure out.

Java DNS resolution hangs forever

We are also trying to solve this problem. Looks like this is due to glibc bug: https://bugzilla.kernel.org/show_bug.cgi?id=99671 or the kernel bug: https://bugzilla.redhat.com/show_bug.cgi?id=1209433 depending on who you ask ;)

Also worth reading: https://access.redhat.com/security/cve/cve-2013-7423 and https://alas.aws.amazon.com/ALAS-2015-617.html

To confirm that this is indeed the case attach gdb to the java process:

gdb --pid <JavaProcessPid>

then from gdb:

info threads 

find a thread that does recvmsg:

thread <HangingThreadId>

and then

backtrace 

and if you see something like this then you know that glibc/kernel upgrade will help:

#0  0x00007fc726ff27cd in recvmsg () from /lib64/libc.so.6
#1 0x00007fc727018765 in make_request () from /lib64/libc.so.6
#2 0x00007fc727018b9a in __check_pf () from /lib64/libc.so.6
#3 0x00007fc726fdbd57 in getaddrinfo () from /lib64/libc.so.6
#4 0x00007fc706dd9635 in Java_java_net_Inet6AddressImpl_lookupAllHostAddr () from /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.65-0.b17.el6_7.x86_64/jre/lib/amd64/libnet.so

Update: Looks like the kernel wins. Please see this thread: http://www.gossamer-threads.com/lists/linux/kernel/2264958 for details.
Also there is a tool to verify that your system is affected by the kernel bug you can use this simple program: https://gist.github.com/stevenschlansker/6ad46c5ccb22bc4f3473

to verify:

curl -o pf_dump.c https://gist.githubusercontent.com/stevenschlansker/6ad46c5ccb22bc4f3473/raw/22cfe72f6708de1e3468c1e0fa3888aafae42db4/pf_dump.c
gcc pf_dump.c -pthread -o pf_dump
./pf_dump

And if the output is:

[26170] glibc: check_pf: netlink socket read timeout
Aborted

Then the system is affected. If the output is something like:

exit success [7618] exit success [7265] exit success

then the system is ok.
In the AWS context, upgrading AMIs to (2016.3.2) with the new kernel seems to have fixed the problem.

A strange UnknownHostException

i have had the same exception and solved it by setting my hostname manually in /etc/hosts for the 'localhost' entry both.

127.0.0.1       localhost DL006285-linux

# special IPv6 addresses
::1 localhost ipv6-localhost ipv6-loopback DL006285-linux

Connect to external mongo database (java)

Looks like a DNS resolution problem at some point in the stack. java.net.UnknownHostException is "Thrown to indicate that the IP address of a host could not be determined".

Problem with Java

The problem may be with Java itself. There is a known issue with Java and IPv6. You can try setting the java.net.preferIPv4Stack system property to true to see if that fixes the issue.

As a parameter to the java command when launching your JVM:

java -Djava.net.preferIPv4Stack=true YourMainClass

Or programmatically:

System.setProperty("java.net.preferIPv4Stack" , "true");

You can also try upgrading to the latest version of Java to get all the bug fixes that come with it.

Problem with your DNS server or configuration

The issue may also be with the DNS configuration on your laptop/machine. You can use dig to see what that DNS lookup returns. Below is the output of what I get from my laptop. You can also use this web version of dig to see what you should be getting.

% dig ds047037.mongolab.com

; <<>> DiG 9.8.3-P1 <<>> ds047037.mongolab.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 20375
;; flags: qr rd ra; QUERY: 1, ANSWER: 4, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;ds047037.mongolab.com. IN A

;; ANSWER SECTION:
ds047037.mongolab.com. 120 IN CNAME ds047037-a.mongolab.com.
ds047037-a.mongolab.com. 120 IN CNAME h000432.mongolab.com.
h000432.mongolab.com. 120 IN CNAME ec2-46-51-159-130.eu-west-1.compute.amazonaws.com.
ec2-46-51-159-130.eu-west-1.compute.amazonaws.com. 300 IN A 46.51.159.130

;; Query time: 23 msec
;; SERVER: 192.168.1.1#53(192.168.1.1)
;; WHEN: Sat Jan 12 13:22:24 2013
;; MSG SIZE rcvd: 162

If you confirm that your DNS configuration / server is the issue, you will need to determine which DNS servers you're using and then contact the owner / administrator or contact your ISP to make sure they're configured as they should be.

DNS Unlocker Adware not getting removed from firefox with any tool or manually

It looks like you have downloaded some MalWare crap. See

Download.com and Others Bundle Superfish-Style HTTPS Breaking Adware.

It may help you in your situation.

Developing for multiple monitors

Few random tips:

  • If multiple windows can be open at one time, allow users to have them on separate screens. Seems obvious, but some very popular apps (e.g. Visual Studio) fail miserably at this.
  • Remember the position of the last opened window, and open new windows on the same screen as before. However, sometimes users switch between multiple and single-display (e.g. docking a laptop with an external CRT), so watch cover this case as well.
  • Consider how your particular users work, and how having two maximized windows simultaneously might help. Often, there is a (fairly passive) window for reference (e.g. a web browser/help) and an active window for data entry (e.g. editor/database) that users switch between.
  • Do not put toolboxes/toolbars on a different window than objects they operate on (it's inconvenient to move the mouse so far).


Related Topics



Leave a reply



Submit