Description
When reading from the InputStream provided by StreamIoHandler, the read can block indefinitely if the client closes the connection.
This is caused by the StreamIoHandler not closing the provided streams in the sessionClosed() method. The InputStream remains open, waiting for more data. After many connections, there may be a large number of "zombie" threads that will never wake up.
I will upload a patch to fix this problem. In the mean time, a workaround I am currently using follows. It keeps track of the InputStream for each session, and closes it when the session closes. This ensures the thread has a chance to terminate properly.
protected final void processStreamIo(
IoSession session,
InputStream in,
OutputStream out)
// Ensures session's InputStream gets closed, so the thread doesn't lock up
private Map<IoSession,InputStream> sessionStreams = new HashMap<IoSession, InputStream>();
@Override
public void sessionClosed(IoSession session) throws Exception {
super.sessionClosed(session);
InputStream is = sessionStreams.get(session);
if(null != is) {
try
catch(IOException ioe)
{ // Ignore } }
}