RFR: 8293696: java/nio/channels/DatagramChannel/SelectWhenRefused.java fails with "Unexpected wakeup" [v7]

Mark Sheppard msheppar at openjdk.org
Fri Nov 4 12:30:31 UTC 2022


On Fri, 4 Nov 2022 12:20:33 GMT, Darragh Clarke <duke at openjdk.org> wrote:

>> Added logging to SelectWhenRefused for an intermittent failure caused by unexpected wakeups, this includes trying to receive data if there is any available to identify where it is coming from.
>> 
>> I also set the test to run in othervm mode which should reduce the chances of this failure happening in the first place.
>
> Darragh Clarke has updated the pull request incrementally with one additional commit since the last revision:
> 
>   cleanup

you might consider a refactor extract method, for each of the test scenarios such that 
each loop contains an invocation of a static method encapsulating that test scenario 
For example, scenario 1 == testNoPUEUnconnected, scenario 2 == testPUEConnected, 
scenario 3 == testNoPUEDisconnected, and each method has a brief description 
of the test scenario and retry policy. As such, first test retry loop might look like





       try {
            dc.configureBlocking(false);
            dc.register(sel, SelectionKey.OP_READ);

            for (int i = 0; i < MAX_TRIES; i++) {
                if (!testNoPUEUnconnected(dc, refuser, sel, i)) {
                    break;
                }
              }
       ….

    /*
     * Send a datagram to non existent unconnected UDP end point 
     * This shouldn't result in an PortUnreachableException
     * Handle unexpected read events on the senders DC with
     * retry when message received is external. Ignore
     * receipt of own message
     */
    static boolean testNoPUEUnconnected (DatagramChannel sender,
                                         SocketAddress recipient,
                                         Selector selector,
                                         int retryCount) throws IOException {
        /* Test 1: not connected so ICMP port unreachable should not be received */
        sendDatagram(sender, recipient);
        int n = selector.select(2000);
        if (n > 0) {
                    boolean receivedExternalDatagram = checkUnexpectedWakeup(selector.selectedKeys());
                    selector.selectedKeys().clear();
                    if (receivedExternalDatagram) {
                        if (i < MAX_TRIES - 1) {
                           return true;
                    }
                    // BindException will be thrown if another service is using
                    // our expected refuser port, cannot run just exit.
                    DatagramChannel.open().bind(refuser).close();
                    throw new RuntimeException("Unexpected wakeup");
                }
        }
        return false;
    }

//  E&OE — I haven’t tested the above 

Or alternatively encapsulate the retry loop into the scenario methods also ??

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

PR: https://git.openjdk.org/jdk/pull/10851


More information about the nio-dev mailing list