RFR: 8287580: (se) CancelledKeyException during channel registration

Vyom Tewari vtewari at openjdk.java.net
Thu Jun 2 12:37:42 UTC 2022


On Thu, 2 Jun 2022 09:57:39 GMT, Alan Bateman <alanb at openjdk.org> wrote:

>> src/java.base/share/classes/sun/nio/ch/SelectorImpl.java line 229:
>> 
>>> 227:             k.cancel();
>>> 228:             throw e;
>>> 229:         } catch (CancelledKeyException ignored) {
>> 
>> Hi Brian, what about adding the selection key to “keys”  after we set the interesOps ? I do not see any side effect of doing this.
>> 
>>          // it may be observed by a thread iterating over the selector's key set.
>> -        keys.add(k);
>>          try {
>>              k.interestOps(ops);
>> +            keys.add(k);
>>          } catch (ClosedSelectorException e) {
>
>> Hi Brian, what about adding the selection key to “keys” after we set the interesOps ? I do not see any side effect of doing this.
> 
> That would mean a selection key could be selected before it added to the selector's key set. So I don't think it is feasible, at least not without working through the spec implications.

agreed,as soon as we set the  interestOps on key, native  system call can select the particular fd which is not yet added to the selector key set.

-------------

PR: https://git.openjdk.java.net/jdk/pull/8978


More information about the nio-dev mailing list