Cleaning up ChannelContext between HTTP requests

danotsky danotsky at gmail.com
Tue Jan 19 01:14:04 EST 2010


I've got an HTTP server setup on Netty.  Upon receiving each HTTP request I'm
creating a new context and attaching it to the Channel.  When writing the
response, I add a listener to the write future that does some bookkeeping
and then clears the context and leaves the channel ready for the next
request.  For now I'm preventing multiple outstanding requests (pipelining)
by closing the connection when a new request comes in before the previous
request has cleaned up.  

The problem I'm running into is that occasionally when sending serial
requests over a single connection, a new request comes in before the
previous was cleaned up.  I assumed that that a future listener setup on the
response write would always execute before a message received event occurred
for the next request, but this appears to not be the case since occasionally
the next request comes in before the write future is executed.  

I control the client in this case and I know that it's not sending the next
request until it fully reads the previous response, so it really is a race
condition in the server.  

Is this behavior behavior expected or might it be a bug?  If it's expected,
what's the best way to handle this?  I don't seem to have a way to cleanup
after a write completes in a spot where I know it's before the next request
is read.

Thanks.


-- 
View this message in context: http://n2.nabble.com/Cleaning-up-ChannelContext-between-HTTP-requests-tp4418312p4418312.html
Sent from the Netty User Group mailing list archive at Nabble.com.


More information about the netty-users mailing list