FULL PRODUCT VERSION : Sun JDK 1.6.0 [sun-jdk-1.6] ADDITIONAL OS VERSION INFORMATION : Linux camelion 2.6.20-gentoo #1 PREEMPT Sun Feb 11 23:37:40 CET 2007 i686 Intel(R) ntium(R) 4 Mobile CPU 1.80GHz GenuineIntel GNU/Linux A DESCRIPTION OF THE PROBLEM : The httpServer is not closing the connection after the request is completed. the number of open connections increase until the system limit is reached. STEPS TO FOLLOW TO REPRODUCE THE PROBLEM : Compile the attached code and start using javac WebApp.java java WebApp open a second terminal while true; do curl http://localhost:8123/test; done open a third terminal netstat -atunp | grep 8123 | wc -l EXPECTED VERSUS ACTUAL BEHAVIOR : EXPECTED - The connections should be closed after the request is processed. ACTUAL - Connection keeps open. REPRODUCIBILITY : This bug can be reproduced always. ---------- BEGIN SOURCE ---------- import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.InetSocketAddress; import com.sun.net.httpserver.HttpContext; import com.sun.net.httpserver.HttpExchange; import com.sun.net.httpserver.HttpHandler; import com.sun.net.httpserver.HttpServer; public class WebApp implements HttpHandler { public static void main(String[] args) { try { HttpServer server = HttpServer.create(new InetSocketAddress(8123),0); HttpContext ctx = server.createContext("/test",new WebApp()); server.setExecutor(null); server.start(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public void handle(HttpExchange t) throws IOException { InputStream is = t.getRequestBody(); byte[] bBody = new byte[1000]; int count = is.read(bBody); String sBody = bBody.toString(); String response = "testmessage\n"; t.sendResponseHeaders(200, response.length()); OutputStream os = t.getResponseBody(); os.write(response.getBytes()); is.close(); os.close(); t.close(); } } ---------- END SOURCE ----------
|