JDK 9 RFR of 8175209: Account for race condition in java/nio/channels/AsynchronousSocketChannel/Basic.java

Brian Burkhalter brian.burkhalter at oracle.com
Tue Feb 28 16:25:21 UTC 2017

Please review this test bug fix at your convenience.

Issue:	https://bugs.openjdk.java.net/browse/JDK-8175209
Patch:	http://cr.openjdk.java.net/~bpb/8175209/webrev.00/

This test was failing due to a WritePendingException not occurring when expected. This is presumably due to the writes in the sequence of chained writes on the channel still being completed immediately despite the 5 second wait for the socket buffer to fill. When the writes are immediate there is a tiny time slice between when the channel is re-enabled for writing and when the handler is invoked. If the call to the write which is supposed to provoke the WritePendingException happens to occur in this small time window the exception will not be thrown and the test will fail. The change here is to record the most recent time at which CompletionHandler.completed() has been called and pause repeatedly until this time no longer changes. With this change the test passes on all platforms and is slightly faster as the total time paused is 2-3 seconds instead of 5. Assuming this fix is good, likely [1] will no longer occur and may eventually be resolved.



[1] https://bugs.openjdk.java.net/browse/JDK-8161991

More information about the nio-dev mailing list