Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6644274

HTTP server leaks resources

XMLWordPrintable

    • generic
    • generic

      Consider the following light Java code:

      import com.sun.net.httpserver.HttpContext;
      import com.sun.net.httpserver.HttpServer;
      import java.net.InetSocketAddress;

      public class Test {

         public static void main(String[] args) throws Exception {
             InetSocketAddress inetAddress = new InetSocketAddress("localhost", 65436);
             while (true) {
                 HttpServer server = HttpServer.create(inetAddress,0);
                 HttpContext context = server.createContext("/test");
                 server.start();
                 // Uncomment the following line and the test case will not fail
                 //Thread.sleep(100);
                 server.removeContext(context);
                 server.stop(0);
             }
         }
      }

      When you run it (with JAX-WS release 2.1.3-20071106 + JDK 5 on a four way Sparc)
      you go out of resources:

      Exception in thread "main" java.io.IOException: Too many open files
              at sun.nio.ch.IOUtil.initPipe(Native Method)
              at sun.nio.ch.DevPollSelectorImpl.<init>(DevPollSelectorImpl.java:51)
              at
      sun.nio.ch.DevPollSelectorProvider.openSelector(DevPollSelectorProvider.java:18)
              at java.nio.channels.Selector.open(Selector.java:209)
              at sun.net.httpserver.ServerImpl.<init>(ServerImpl.java:73)
              at sun.net.httpserver.HttpServerImpl.<init>(HttpServerImpl.java:32)
              at
      sun.net.httpserver.DefaultHttpServerProvider.createHttpServer(DefaultHttpServerProvider.java:17)
              at com.sun.net.httpserver.HttpServer.create(HttpServer.java:111)
              at Test.main(Test.java:13)

      If you uncomment the 100 milliseconds sleep in the Java code, the test behaves well.

            michaelm Michael McMahon
            yjoan Yves Joan (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: