JDK-6276939 : InetAddress deadlock under low-memory conditions
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2005-05-27
  • Updated: 2011-03-16
  • Resolved: 2011-03-16
Related Reports
Duplicate :  
Description
From InetAddress.java:

            } finally {
                // Cache the address.
                cacheAddress(host, obj, success);
                // Delete the host from the lookupTable, and
                // notify all threads waiting for the monitor
                // for lookupTable.
                updateLookupTable(host);
            }

If cacheAddress() throws an exception, such as OutOfMemoryError,
then updateLookupTable() will not get called.  This will
cause future lookups of this host to wait forever in
checkLookupTable().

###@###.### 2005-05-27 00:30:53 GMT

A test case follows:

----
import java.net.InetAddress;
import java.net.UnknownHostException;

public class test2 {
    public static void main(String args[]) {
        System.setProperty("sun.simulate.outofmemory", "true");
        try {
            InetAddress.getByName("localhost");
        } catch (Exception e) {
        }
        System.setProperty("sun.simulate.outofmemory", "false");
        try {
            InetAddress.getByName("localhost");
        } catch (Exception e) {
        }
    }
}
----

Because the out-of-memory error needs to happen in a very specific
place, the easiest way to reproduce the problem is either to
modify cacheAddress() in InetAddress.java to do something like:

if (System.getProperty("sun.simulate.outofmemory").equals("true")) {
    throw new RuntimeException("Out of memory");
}

or run inside a debugger and force an out-of-memory error at
the correct time.

###@###.### 2005-06-16 07:01:27 GMT

Comments
EVALUATION Let's say that the application does not catch the OutOfMemoryError, but the application does have more than one thread. One thread exiting because of an uncaught OutOfMemoryError will not shutdown the entire application. The remaining threads will still be vulnerable to the deadlock.
05-04-2007

EVALUATION The bug report is incomplete. Can the originator provide some test case to show the deadlock? ###@###.### 2005-06-16 02:58:59 GMT The java.lang.OutOfMemoryError is a java.lang.Error. The javadoc for java.lang.Error reads: "An Error is a subclass of Throwable that indicates serious problems that a reasonable application should not try to catch. Most such errors are abnormal conditions." So it's reasonable for InetAddress not to address such conditions. Will close the bug. ###@###.### 2005-07-20 02:49:01 GMT
01-06-2005