Odd timing of channelConnected(), Netty 3.1.0beta2

IanS iswett at yahoo.com
Mon May 25 16:07:00 EDT 2009


Yes, in this case I'm opening, sending, and closing, and not explicitly
waiting for it to write before closing.  I am going to change that in this
case, but I can imagine a situation where another thread opens a client
connection just as a different thread shuts down the application.  

Part of my concern was the out of order calls, where I was getting the
channelConnected() call after the channelDisconnected() call for the same
channel.  I don't fully understand how that would be happening?  I think it
would be nice to have the guarantee of callbacks in order of channel state
change if that is possible, but it may not be.  


FYI, I've really enjoyed using Netty and my networking code is now smaller
with Netty + Google Protocol Buffers than it was when I was using HTTP, as
well as being much faster.  

Thanks, Ian


Trustin Lee-2 wrote:
> 
> Hi Ian,
> 
> IIUC, you are getting the ClosedChannelException at
> NioWorker.cleanUpWriteBuffer() on the client side and you are sending a
> message and close the connection immediately, right?  It's normal that
> Channel.isConnected() can return false even in channelConnected() if the
> connection has been closed very quickly.  Channel might have been
> connected at the point where the channelConnected event is fired, but not
> at the point where the handler is actually executed.
> 
> If so, do you call Channel.close() *after* the ChannelFuture returned by
> Channel.write() is set as 'done'?  If not, you have a high chance of
> getting such a race condition because Channel.write() in Netty never
> blocks in NIO transport.
> 
> Usually, the following idiom is used to make sure Channel.close() is
> called after last write request is sent:
> 
>     // Close the connection when writing the last message finishes.
>     ch.write(lastMessage).addListener(ChannelFutureListener.CLOSE);
> 
> HTH,
> Trustin
> 
> -- 
> - Trustin Lee, http://gleamynode.net/
> _______________________________________________
> netty-users mailing list
> netty-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/netty-users
> 
> 

-- 
View this message in context: http://n2.nabble.com/Odd-timing-of-channelConnected%28%29%2C-Netty-3.1.0beta2-tp2966093p2971439.html
Sent from the Netty User Group mailing list archive at Nabble.com.




More information about the netty-users mailing list