netty/netty — Issue #100: Too many open files may not be handled right. 
Author: marchywka
Created: 2011-12-02 14:55:20+00:00
State: open

Hi,
I just downloaded netty , 3.2.7-Final , recently and started slamming a home made server based on it. I began getting clients hanging
which suggested that accept was throwing without closing the serversocket. Indeed, that is what I found,

java.io.IOException: Too many open files
at sun.nio.ch.ServerSocketChannelImpl.accept0(Native Method)
at sun.nio.ch.ServerSocketChannelImpl.accept(ServerSocketChannelImpl.java:226)
at org.jboss.netty.channel.socket.nio.NioServerSocketPipelineSink$Boss.run(NioServerSocketPipelineSink.java:249)
at org.jboss.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108)
at org.jboss.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:44)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)

I also was getting the logging call in the exception handler to throw an Error due to fact that I don't have logging setup.
This leaves the server socket bound but with no one to accept connections. I added some code to run() method in

org/jboss/netty/channel/socket/nio/NioServerSocketPipelineSink.java

to catch Throwable around the logging request and close the server socket in finally block but I'm sure there
is a better way to approach this for those familiar with the netty code. In any case, this would seem to create a
bad failure mode if left as it currently is and it was not obvious to me how to deal with this in higher level code without
changing the catch and finally blocks in this code. When I saw this in my own code, I closed the serversocket and bound a new
one but again there is probably a better way to handle this.

Thanks.

} finally {
channel.shutdownLock.unlock();
// mjm
try { channel.socket.close(); } catch (Exception eee) {}
closeSelector();
}