JDK-5053708 : DNS provider does not cleanup resources properly
  • Type: Bug
  • Component: core-libs
  • Sub-Component: javax.naming
  • Affected Version: 5.0,5.0u4
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic,solaris_10
  • CPU: generic,sparc
  • Submitted: 2004-05-27
  • Updated: 2007-04-17
  • Resolved: 2007-04-17
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other JDK 6 JDK 7
1.4.2_15Fixed 6u2Fixed 7 b12Fixed
Related Reports
Duplicate :  
Relates :  
Relates :  
Description
The DNS provider context does not cleanup the network resources
upon a close.

This problem was posted on the JNDI forum at java.sun.com

import java.net.*;
import javax.naming.*;
import javax.naming.directory.*;
import java.util.*;

public class SocketLeak {
    public static void main(String argv[]) throws Exception {
        Map map = new HashMap();
        Hashtable env= new Hashtable();

        env.put(Context.INITIAL_CONTEXT_FACTORY,
                "com.sun.jndi.dns.DnsContextFactory");
        env.put(Context.PROVIDER_URL,"dns://xxx.xxx.xxx.xxx");
        int count = 0;

        while(true) {
            DirContext ctx = new InitialDirContext(env);
            ctx.close();
            ctx = null;
            count++;
            System.out.println(count);
        }
    }
}


The above program loops for around 1020 times on solaris 8, after which it runs
out of file descriptors, and fails with an exception below.

Exception in thread "main" javax.naming.ConfigurationException.  Root exception is java.net.SocketException: Too many open files
        at java.net.PlainDatagramSocketImpl.datagramSocketCreate(Native Method)
        at java.net.PlainDatagramSocketImpl.create(PlainDatagramSocketImpl.java:53)
        at java.net.DatagramSocket.createImpl(DatagramSocket.java:278)
        at java.net.DatagramSocket.<init>(DatagramSocket.java:127)
        at com.sun.jndi.dns.DnsClient.<init>(DnsClient.java:81)
        at com.sun.jndi.dns.Resolver.<init>(Resolver.java:33)
        at com.sun.jndi.dns.DnsContext.<init>(DnsContext.java:78)
        at com.sun.jndi.dns.DnsContextFactory.UrlToContext(DnsContextFactory.java:73)
        at com.sun.jndi.dns.DnsContextFactory.getInitialContext(DnsContextFactory.java:41)
        at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662)
        at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243)
        at javax.naming.InitialContext.init(InitialContext.java:219)
        at javax.naming.InitialContext.<init>(InitialContext.java:195)
        at javax.naming.directory.InitialDirContext.<init>(InitialDirContext.java:80)
        at SocketLeak.main(SocketLeak.java:17)

Comments
SUGGESTED FIX --- DnsContext.java Thu Mar 29 13:53:55 2007 *** 123,135 **** retries = ctx.retries; lookupCT = ctx.lookupCT; } public void close() { ! // When adding anything here, consider whether BindingEnumeration ! // needs a finalizer. } //---------- Environment operations /* --- 123,137 ---- retries = ctx.retries; lookupCT = ctx.lookupCT; } public void close() { ! if (resolver != null) { ! resolver.close(); ! resolver = null; } + } --- Resolver.java Thu Mar 29 13:54:25 2007 *** 44,53 **** --- 44,54 ---- dnsClient = new DnsClient(servers, timeout, retries); } public void close() { dnsClient.close(); + dnsClient = null; }
03-05-2007

EVALUATION See comments
02-09-2004