netty/netty — pull request #1721 by wgallagher (2013-08-09 16:03:45+00:00)
Title: intermittent:  local channel sometimes sends messages after close

A local channel can receive messages after it has been closed. This is the result of a race condition in DefaultLocalChannel.flushWriteBuffer:

e.getFuture().setSuccess();
fireMessageReceived(pairedChannel, e.getMessage());
fireWriteComplete(this, 1);

The future listener in this case is HttpConnectionHandler.ClosingChannelFutureListener.

The problem is that the future.setSuccess() races with the fireMessageReceived. Moving the setSuccess to happen after the message is sent helps but doesn't completely remove the race:

fireMessageReceived(pairedChannel, e.getMessage());
fireWriteComplete(this, 1);
e.getFuture().setSuccess();