What exactly happens when netty server calls disconnect()
"이희승 (Trustin Lee)"
trustin at gmail.com
Thu Nov 11 03:57:12 EST 2010
tsuna wrote:
> On Fri, Aug 27, 2010 at 11:32 AM, Daniel Ferber <dffforum at gmail.com> wrote:
>> I might be missing something about half-closed socket, therefore I would
>> like to ask for advices.
>>
>> According to TCP specs, a socket could stay half-closed for a while: one
>> peer signaled that it has finished sending, but the other is still allows to
>> send. But I cannot reproduce the half-closed state with my netty experiment.
>
> So tonight while I was firefighting some production problem at
> StumbleUpon, I ended up looking for the answer to this question about
> half-closed connections and Netty's behavior. I think the code in
> Netty explicitly prevents the use of half-closed sockets, although I'm
> not entirely sure.
>
> All the real stuff when using NIO sockets happens in
> netty/channel/socket/nio/NioWorker.java. I'm not very familiar with
> NIO's Selector API, but my understanding is that on Linux it's
> wrapping epoll(), so I assume it has a similar semantics. When the
> remote peer closes the connection, I think the Selector will indicate
> that the channel is readable but read() will return -1 to indicate
> "end-of-stream". NioWorker#read closes the channel when this happens.
> Thus as soon as the remote peer closes its side of the connection,
> Netty will do so on the other side too.
> When you close your side of the connection by calling disconnect(),
> however, you end up in
> netty/channel/socket/nio/NioClientSocketPipelineSink.java or similar,
> where eventSunk() calls close() on the NioWorker. The NioWorker then
> does channel.setClosed(). I couldn't determine whether this would
> prevent the code from reading from socket after it was closed. It
> seems that it would work because NioWorker#run doesn't check the state
> of the channel, it's just waiting on the Selector to get data from the
> socket and then fires a ChannelBuffer downstream.
Yeah, Netty doesn't support half-closed connection. I didn't really
know half-closed connections are used that often. I guess we need some
API changes to support that. Any idea appreciated.
Thanks
--
Trustin Lee - http://gleamynode.net/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 290 bytes
Desc: OpenPGP digital signature
Url : http://lists.jboss.org/pipermail/netty-users/attachments/20101111/fc814dba/attachment.bin
More information about the netty-users
mailing list