RFR: 8336339: (se) SelectionKey.interestOps(int) should not throw ClosedSelectorException
Alan Bateman
alanb at openjdk.org
Sat Jul 20 15:35:05 UTC 2024
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.
-------------
Commit messages:
- Initial commit
Changes: https://git.openjdk.org/jdk/pull/20269/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=20269&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8336339
Stats: 162 lines in 8 files changed: 128 ins; 25 del; 9 mod
Patch: https://git.openjdk.org/jdk/pull/20269.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/20269/head:pull/20269
PR: https://git.openjdk.org/jdk/pull/20269
More information about the nio-dev
mailing list