Whistles

geekery and stuff

Java Internet Connection Problems in Debian

View Comments

The case is this: I have three computers running different versions of Debian GNU/Linux. The server has (stable) Lenny, my desktop computer at work has Sid (unstable) and my laptop has Squeeze (testing.) I want to install version 3 Glassfish application server to all of these.

The installation at the (Lenny) production server went straightforward, download the file, unzip it, then type

$ glassfish-v3/bin/asadmin start-domain

and let it start. Ordinary installation task ends here.

Then I wanted to repeat this on my desktop system and ended with an intense Googling and testing process.

The problem is this: When I repeat the above procedure in my desktop system and in my laptop, it reports a fault like this:

There is a process already using the admin port 4848 -- it probably is
another instance of a GlassFish server.
Command start-domain failed.

Then I wrote:

$ netstat -tlp --numeric-ports | grep 4848

Nothing returns, hence there is no process listening port 4848.

I googled a bit, people write about different kinds of workarounds related to this error, mostly related with /etc/hosts.

I played with /etc/hosts a bit, changing localhost addresses, adding and removing my LAN address as localhost, turning off interfaces, checking routes to no avail.

In the meantime I changed my java installations from OpenJDK to Sun JDK with

# update-alternatives --config java

and this also didn’t change anything.

I wrote the problem to java.net forums. Someone asked me to add another domain, so did I and nothing changed.

I purged Glassfish and downloaded NetBeans 6.8 and Glassfish bundle. It too couldn’t start Glassfish. Moreover, when Netbeans started, I noticed, I can’t connect to the Internet too.

My Java Internet connection was off.

This is a larger and more severe bug than a minor Glassfish problem and this was (against common sense) good news. It’s always easier to correct a large bug then a small one.

I then repeat the process above, playing with /etc/hosts, checking java configuration files in /etc and purging packages and reinstalling. This time, I tried to connect to Internet with a small program I found from Stack Overflow.

public static boolean isInternetReachable()
{
try {
    //      SecurityManager security =3D System.getSecurityManager();
    //      System.out.println(security.toString());
    //make a URL to a known source
    URL url =3D new URL("http://www.google.com");
    //open a connection to that source
    HttpURLConnection urlConnect =3D (HttpURLConnection)url.openConnection();
    //trying to retrieve data from the source. If there
    //is no connection, this line will fail
    Object objData =3D urlConnect.getContent();
} catch (UnknownHostException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    return false;
}
catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    return false;
}
return true;

This program resulted in following stack trace:

java.net.NoRouteToHostException: Network is unreachable
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:310)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:176)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:163)
    at java.net.Socket.connect(Socket.java:542)
    at java.net.Socket.connect(Socket.java:492)
    at sun.net.NetworkClient.doConnect(NetworkClient.java:174)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:409)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:530)
    at sun.net.www.http.HttpClient.<init>(HttpClient.java:240)
    at sun.net.www.http.HttpClient.New(HttpClient.java:321)
    at sun.net.www.http.HttpClient.New(HttpClient.java:338)
    at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:814)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:755)
    at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:680)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1005)
    at java.net.URLConnection.getContent(URLConnection.java:705)
    at internetConnection.testConnection.isInternetReachable(testConnection.java:26)
    at internetConnection.testConnection.main(testConnection.java:12)

Then I found somebody complaining about the same problem in NetBeans IRC logs.

Then I read all relevant pieces of code from OpenJDK’s java.net package. The problem, in my opinion, was java.net.InetAddress class’ handling of local addresses. It was simply returning false instead of checking whether an address is local or remote.

But this was to make all network handling of Java obsolote, so there should be some other problem, and there it is:

Quoting Debian Bug Report.

Netbase has recently introduced the sysctl-setting net.ipv6.bindv6only=1 in /etc/sysctl.d/bindv6only.conf and this setting will probably be the default in squeeze.

This setting breaks networking in java, and any traffic will for openjdk always result in a “java.net.NoRouteToHostException: Network is unreachable”.

It should probably be an rc-bug, but setting as important for now, since users can easily rectify the issue.

Quick fix for users hit by this:

sudo sed -i ’s/net.ipv6.bindv6only\ =\ 1/net.ipv6.bindv6only\ =\ 0/’ \ /etc/sysctl.d/bindv6only.conf && sudo invoke-rc.d procps restart

This is present in both Sun’s Java6 and OpenJDK6.

The solution is to type (as root):

# sysctl net.ipv6.bindv6only=0

and everything is fine now. This one line solves problem after 20 hours of active search and tests.

Now, I can (and should) complete the necessary Web Services.

Written by Emre

February 14th, 2010 at 12:25 pm

Posted in Uncategorized

  • Vev
    bloody thanks mate!
  • Cafilubu
    Thanks you!
  • patczar
    Thank you so much that I cannot express it.
  • igogo
    Thank you, man! This fixes famous TopCoder Arena bug also!

    One remark: In my case, for some reason, #sysctl net.ipv6.bindv6only=3D0 results in
    error: "Invalid argument" setting key "net.ipv6.bindv6only"

    But just
    # sysctl net.ipv6.bindv6only=0

    makes the thing.
  • Thanks for the correction, I'm yet to find a decent email plugin behaves well with Markdown for WP.
  • Man, you saved my life!
    Thank you!
  • You're welcome :)
  • Christos
    I have the same problem with Glassfish v3 on Netbeans 6.8, using jdk 1.6.0_u11. I have tried everything. Many installs and unistalls, restarts etc but nothing...
    Could you please explain to me what steps to follow in windows XP to solve my problem??I have to finish my thesis and three days now I am trying to solve this annoying "GlassFish v3 Domain Server cannot start. Port is occupied."
    Thank you in advance, Christos!
  • A permanent solution is to edit /etc/sysctl.d/bindv6only.conf and save the modification there.
blog comments powered by Disqus