RFR: 8264200: java/nio/channels/DatagramChannel/SRTest.java fails intermittently

Conor Cleary ccleary at openjdk.java.net
Tue Apr 6 13:11:27 UTC 2021


On Tue, 6 Apr 2021 11:38:20 GMT, Daniel Fuchs <dfuchs at openjdk.org> wrote:

>> ### Description
>> SRTest.java has been seen to fail intermittently in a similar manner to other recent failures in [DatagramChannel tests](https://github.com/openjdk/jdk/pull/679). With SRTest.java, these failures are associated with a number of issues listed below. Note that XReader refers to both ClassicReader and NioReader classes. Likewise for XWriter.
>> 
>> - Test is run in AgentVM mode.
>> - Receivers bind to wildcard/localhost which has been a source of instability.
>> - Sockets are not closed properly if an exception is thrown, even more of an issue due to test running in AgentVM mode.
>> - An XReader instance will wait forever to receive a `DatagramPacket` if an XSender has not sent one.
>> 
>> ### Fixes
>> To Address these issues, the following was done respective to the order of the Issues above:
>> - Test now runs with `testng/othervm` and uses its own thread pool. Note that the change to testng was not absolutely essential but means that if one test case fails the others will still be run which could provide useful information on why a failure occured.
>> - Receivers now bind to loopback address instead of localhost.
>> - XReader and XWriter classes implement `Autocloseable` and are declared within a try-with-resources block for each test case. As well as this, the test cases are now executed with `CompleteableFuture.allOf(futures)` such that if any Reader or Writer throws an exception during execution, the threads will exit in a safe manner and the exception concerned will be thrown (wrapped in a `CompletionException`).
>> - Test will now timeout with respect to timeout limit of Jtreg which is set to 20 seconds for this test. Note that this is given in the `@run` as `testng/othervm/timeout=20` tag in seconds. See Action Options in Jtreg docs [here](https://openjdk.java.net/jtreg/tag-spec.html).
>
> test/jdk/java/nio/channels/DatagramChannel/SRTest.java line 228:
> 
>> 226:                 SocketAddress sa = dc.receive(bb);
>> 227:                 bb.flip();
>> 228:                 CharBuffer cb = StandardCharsets.US_ASCII.newDecoder().decode(bb);
> 
> If a charset is used, then it should be used consistently - in both classic and nio readers and writers.
> That is, whenever `String::getBytes` is called or `new String(byte[])` is called.

Makes sense, I think I will opt for using `US_ASCII` across all of the classic and nio readers/writers.

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

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


More information about the nio-dev mailing list