RFR: 8332535: Mark java/nio/channels/DatagramChannel/Loopback.java as intermittent [v2]

Daniel Fuchs dfuchs at openjdk.org
Tue Jun 25 17:26:20 UTC 2024


On Tue, 25 Jun 2024 15:49:50 GMT, SendaoYan <syan at openjdk.org> wrote:

>> test/jdk/java/nio/channels/DatagramChannel/Loopback.java line 164:
>> 
>>> 162:                             System.out.format("received %s from %s%n", dst, sender);
>>> 163:                             senderPort = ((InetSocketAddress) sender).getPort();
>>> 164:                             assertTrue(senderPort != localPort, "Unexpected message: localPort=" + localPort);
>> 
>> I wonder if we should add some entropy to the message content and discard any message that we receive whose payload doesn't match what we expect.
>
> Do you mean like this:
> 
> -            ByteBuffer src = ByteBuffer.wrap("hello".getBytes("UTF-8"));
> +            String str = "hello integer" + new Random().nextInt(10000);
> +            ByteBuffer src = ByteBuffer.wrap(str.getBytes("UTF-8"));
> 
> And I don't known how to discard meaasge doesn't match what we expect.

Yes - something like that. System.nanoTime() could work too.
By discard, I mean compare the content of `dst` with what was put in `src` - and if it doesn't match, clear `dst` and continue to go back to select() without even looking at the sender port. You may want to adjust the timeout you pass to select the second time around.
Rationale is: if the payloads do not match then we're just receiving some stray packet probably sent by another (test?) process.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/19314#discussion_r1653247164


More information about the nio-dev mailing list