RFR: 8293696: java/nio/channels/DatagramChannel/SelectWhenRefused.java fails with "Unexpected wakeup" [v4]
Daniel Fuchs
dfuchs at openjdk.org
Wed Nov 2 11:53:31 UTC 2022
On Tue, 1 Nov 2022 19:07:19 GMT, Alan Bateman <alanb at openjdk.org> wrote:
>> I see. So you advise to pass the single key we obtained when registering the channel, to the method, rather than the selected key set. That's OK with me too.
>
> The method need only be passed one parameter, the DatagramChannel or the SelectionKey (key::channel will give you the channel). Right now it is confused because it wants to loop over all selected keys but it doesn't use the key's channel for the receive method. If I were changing this test then I think I would just pass it the DatagramChannel as the selection key is not really interesting. I think I would also change it to check if sa (the sender) is null so that it doesn't print a confusing message when no datagram has been received.
I had a suspicion that maybe the selector could be woken up if the key became invalid - even though since this is a datagram channel and we're not closing it, I don't see how it could happen. If the key is invalid, there would be nothing to read. In addition, `n` is not supposed to be `> 0`, therefore something unexpected is going on. It seems useful to double check our assumptions: n > 0 because the key is active for reading. I'd like to check that. Hence the idea that passing the key was important. And you only want to attempt reading if the key is active for reading. Otherwise we'd get some other kind of exception and we would still not be the wiser. Good point about calling `key::channel` though!
-------------
PR: https://git.openjdk.org/jdk/pull/10851
More information about the nio-dev
mailing list