[kaffe] Sockets remain unclosed

Ito Kazumitsu ito.kazumitsu at hitachi-cable.co.jp
Tue Mar 16 21:52:02 PST 2004

Old story:



  When you use Jetty with Kaffe,  the number of idle sockets
  gradually increases until "too many open files" error may occur.
  The value of Jetty's parameter MaxIdleTimeMs is 10000 ms by default,
  so a new socket is created and thrown away in every 10 seconds.
  Setting MaxIdleTimeMs to a reasonable value will slow down the
  the creation of new sockets and you can avoid "too many open files".

That was not a complete solution.  Although the creation of new sockets
can be slowed down,  the number of sockets still increases gradually.

I patched java/net/ServerSocket.java to see if this problem can be
solved.  The result is satisfactory.

The following patch is against the released version 1.1.4.

--- java/net/ServerSocket.java.orig	Sat Jan 10 02:38:16 2004
+++ java/net/ServerSocket.java	Wed Mar 17 11:59:06 2004
@@ -322,7 +322,16 @@
       sm.checkListen (impl.getLocalPort ());
     Socket socket = new Socket();
-    implAccept (socket);
+    try {
+        implAccept (socket);
+    }
+    catch (IOException e) {
+        try {
+            socket.close ();
+        }
+        catch (IOException _) {}
+        throw e;
+    }
     return socket;

More information about the kaffe mailing list