16473 – [3.4] ServerSocket accept() leaks file descriptors (original) (raw)

Description Bryce McKinlay 2004-07-11 16:12:10 UTC

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").