United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-5061568 : java.net.InetAddress.isReachable() kills Windows networking

Details
Type:
Bug
Submit Date:
2004-06-10
Status:
Resolved
Updated Date:
2004-06-24
Project Name:
JDK
Resolved Date:
2004-06-24
Component:
core-libs
OS:
windows_2000,windows_xp
Sub-Component:
java.net
CPU:
x86
Priority:
P2
Resolution:
Fixed
Affected Versions:
5.0
Fixed Versions:
5.0 (b58)

Related Reports
Duplicate:

Sub Tasks

Description
Name: rmT116609			Date: 06/10/2004


FULL PRODUCT VERSION :
java version "1.5.0-beta2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta2-b51)
Java HotSpot(TM) Client VM (build 1.5.0-beta2-b51, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP sp1

A DESCRIPTION OF THE PROBLEM :
I wrote a simple program that calls java.net.InetAddress.isReachable() at regular intervals, just like the command line program "ping". It workes fine
for about 60-70 minutes (10 minutes in 1.5.0b1) if it pings once a second, but then a lot of strange things started to happen - all networked programs were suddenly acting funny and my network seemed damaged. Sometimes it helps to wait, other times you need to reboot.

A forum user helped me to confirm this in this thread:
<http://forum.java.sun.com/thread.jsp?forum=11&thread=525312&tstart=15&trange=15>
(socket programming: "InetAddress.isReachable kills windows networking?").
He wrote: "I tried it on JDK 1.5 and Windows 2000. It fails after 660 iterations or at 11:03 minutes. The task manager performance monitor shows that it uses an escalating amout of kernel memory, starting at about 40K per iteration and ending at about 350K per iteration. The total kernel memory at start was 45 meg and at failure about 160meg. "
Later he tried it on a Solaris platform:
" I just ran the test on Solaris 9, pinging a Linux host. It ran 1000 iterations with only a couple of times greater than 1ms.", which would indicate that this foremost is a problem in the Windows JVM.

Our best guess is that a finite resource is used up each call, and not returned (at least fast enough).

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the provided program for at least an hour, (pinging for example a reliable local network host).



EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
With a conservative interval of say a ping every other second, I'd expect this to work "forever".
ACTUAL -
Windows networking starts to lag and deny all network applications network access and bandwith.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
No actual java error messages, symptoms are more of general network subsystem (and other OS resources?) degradation.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
/**
 * By:      Fredrik Or???n???us
 * Created: 2004-04-08 12:01:15
 *
 * A simple command line utility taking a network host as only argument and pings
 * it until interrupted using the new Java 1.5.0 method InetAddress.isReachable().
 *
 * isReachableTest will kill your networking when left running for a little while,
 * about 11 minutes on Win XP SP1 with Java 1.5.0 beta1. The call isReachable()
 * escapes down in JNI, so the cause is unknown to me, but the symptoms suggest
 * that for each ping a finite resource is obtained but never returned.
 *
 * Comment out the line "address.isReachable(500);" below and replace it whith
 * something harmless, perhaps a Thread.sleep(16), and you system will be fine
 * when running isReachableTest. Otherwise all your applications using the network
 * will start acting funny. You probably have to reboot, but sometimes it helps
 * just to kill isReachableTest and wait a short while.
 *
 */

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.io.IOException;

public class isReachableTest
{
  public static void main(String[] args)
  {
    if (args.length == 1) {
      InetAddress address = null;
      try {
        address = InetAddress.getByName(args[0]);
      } catch (UnknownHostException e) {
        System.out.println("Cannot lookup host "+args[0]);
        return;
      }
      try {
        if (address.isReachable(5000)) {
          long nanos = 0;
          long millis = 0;
          long iterations = 0;
          while (true) {
            iterations++;
            try {
              nanos = System.nanoTime();
              address.isReachable(500); // this invocation is the offender
              nanos = System.nanoTime()-nanos;
            } catch (IOException e) {
              System.out.println("Failed to reach host");
            }
            millis = Math.round(nanos/Math.pow(10,6));
            System.out.println("Reply from "+address.getHostAddress()+": time="+millis+" ms");
            try {
              Thread.sleep(Math.max(0, 1000-millis));
            } catch (InterruptedException e) {
              break;
            }
          }
          System.out.println("Iterations: "+iterations);
        } else {
          System.out.println("Host "+address.getHostName()+" is not reachable even once.");
        }
      } catch (IOException e) {
        System.out.println("Network error.");
      }
    } else {
      System.out.println("Usage: java isReachableTest <host>");
    }
  }
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Just use it for a short while and let things "cool down" for an unknown amount of time, or reboot regularly.
(Incident Review ID: 276489) 
======================================================================
###@###.### 2004-07-28

                                    

Comments
CONVERTED DATA

BugTraq+ Release Management Values

COMMIT TO FIX:
tiger-rc

FIXED IN:
tiger-rc

INTEGRATED IN:
tiger-b58
tiger-rc


                                     
2004-08-06
EVALUATION

It seems the socket created by the Win32 implementation of isReachable doesn't correctly close the socket, therefore leading to the resource exhaustion as described.
Will fix that for tiger-rc.

###@###.### 2004-06-11
                                     
2004-06-11



Hardware and Software, Engineered to Work Together