RFR: 8336339: (se) SelectionKey.interestOps(int) should not throw ClosedSelectorException [v2]
Jaikiran Pai
jpai at openjdk.org
Mon Jul 22 13:42:34 UTC 2024
On Sun, 21 Jul 2024 06:58:01 GMT, Alan Bateman <alanb at openjdk.org> wrote:
>> If a Selector is closed at around the same time that a registered key's interestOps (or variants) are used to change the interest ops then interestOps may (incorrectly) throw ClosedSelectorException (CSE) These methods are only specified to throw IAE or CancelledKeyException. Related is that closing a Selector ay around the same time that a channel is initially registered that can with NPE when attempting to remove the key for the channel's registration with the selector.
>>
>> The issue with interestOps dates from JDK 11 when the Selector were mostly re-implemented. The issue with register racing with close may date back further. The Selector implementations are updated to just queue the update so that CSE is not thrown. An option here would be to not queue or remove the update when racing with close but it's not worth it. For the NPE, the AbstractSelectableChannel.removeKey checks if the keys array has been initialized, which is consistent with other access.
>
> Alan Bateman has updated the pull request incrementally with one additional commit since the last revision:
>
> raceRegisterAndClose fix
Based on the provided context, the changes look OK to me.
-------------
Marked as reviewed by jpai (Reviewer).
PR Review: https://git.openjdk.org/jdk/pull/20269#pullrequestreview-2191612272
More information about the nio-dev
mailing list