Integrated: 8336339: (se) SelectionKey.interestOps(int) should not throw ClosedSelectorException
Alan Bateman
alanb at openjdk.org
Tue Jul 23 05:16:39 UTC 2024
On Sat, 20 Jul 2024 12:52:09 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.
This pull request has now been integrated.
Changeset: 9f03f687
Author: Alan Bateman <alanb at openjdk.org>
URL: https://git.openjdk.org/jdk/commit/9f03f687556ee61436a1cb8c89ff063a7cbeaa51
Stats: 161 lines in 8 files changed: 127 ins; 25 del; 9 mod
8336339: (se) SelectionKey.interestOps(int) should not throw ClosedSelectorException
Reviewed-by: jpai, bpb
-------------
PR: https://git.openjdk.org/jdk/pull/20269
More information about the nio-dev
mailing list