As reported by Eric Wong: In version 3.4.0/1, ServerSocket.accept() creates a new Socket() and then in the process invoke Socket.getImpl(), which goes something like this: ----- SocketImpl getImpl() throws SocketException try { if (!implCreated) { impl.create(true); implCreated = true; } } catch (IOException e) { throw new SocketException(e.getMessage()); } return impl; ----- But create(true) alone will cause natPlainSocketImplPosix.cc (depending on the platform) to create a fresh yet never-been-used socket descriptor. As a result, lsof will show: >> socktest 31812 root 8u sock 0,0 1364355 can't identify protocol So each ServerSocket.accept() call will generate additional descriptor until we get EMFILE error ("Too many open files").
I can confirm Eric's report.
Created attachment 6721 [details] Test case
Subject: Bug 16473 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-3_4-branch Changes by: bryce@gcc.gnu.org 2004-07-11 16:42:29 Modified files: libjava : ChangeLog libjava/java/net: ServerSocket.java Socket.java Log message: 2004-07-11 Michael Koch <konqueror@gmx.de> PR libgcj/16473 * java/net/ServerSocket.java (accept): Don't create two client sockets when accepting connections. * java/net/Socket.java (impl): Made package-private. (implCreated): Likewise. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.2562.2.18&r2=1.2562.2.19 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/java/net/ServerSocket.java.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.34.4.1&r2=1.34.4.2 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/java/net/Socket.java.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.33.4.1&r2=1.33.4.2
Fix checked in.