Behaviour of SocketChannelImpl.close() in Java11 (ea+12)

Norman Maurer norman.maurer at googlemail.com
Sun May 13 07:40:21 UTC 2018



> Am 13.05.2018 um 09:36 schrieb Alan Bateman <Alan.Bateman at oracle.com>:
> 
>> On 11/05/2018 20:40, Norman Maurer wrote:
>> :
>> Interesting enough I never noticed this javadoc and just assumed it would work the same way as when I just do it via C, which also works for non-blocking sockets (at least with SO_LINGER 0).
>> 
> The awkward case is enabling linger to a value > 0 as that means the underlying close(2) may potentially block. This gets problematic for selection operations that may have to close a lot of sockets (due to close being called on channels registered with the Selector).

Agree... we saw this exact problem in Netty when someone used 10 seconds and the tried to close sockets which ended up blocking the EventLoop (IO thread).

> 
> There was no intention to break the SO_LINGER = 0 case when this code was refactored a few months ago. We can get that working again, at least for cases where the closed channels are promptly flushed from the Selectors that they are registered with. I have changes that I will bring here for review soon.

Sounds good �� I will happily review the changes and try out with Netty unit tests.

> 
> -Alan.


More information about the nio-dev mailing list