Ignore some test-flakiness when using Java11+ due outstanding Java11 bug. (#7984)

Motivation:

Java11 disallow draining any remaining bytes from the socket if a write causes a connection reset. This should be completely safe to do. At the moment if a write is causing a connection-reset you basically loose all the pending bytes that are sitting on the socket and are waiting to be read.

This happens because SocketOutputStream.write(…) may call AbstractPlainSocketImpl.setConnectionReset(…). Once this method is called any read(…) call will just throw a SocketException without even attempt to read any remaining data.

This is related:
 - https://bugs.openjdk.java.net/browse/JDK-8199329
 - http://hg.openjdk.java.net/jdk/jdk/rev/92cca24c8807
 - http://mail.openjdk.java.net/pipermail/net-dev/2018-May/011511.html

Modifications:

Tolarate if remaining bytes could not be read when using OIO.

Result:

Be able to build Netty and run testsuite while using Java11
This commit is contained in:
Norman Maurer 2018-05-29 19:48:40 +02:00 committed by GitHub
parent 0c6f077c18
commit 4b728cd5bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -33,7 +33,9 @@ import io.netty.channel.socket.ChannelInputShutdownEvent;
import io.netty.channel.socket.ChannelInputShutdownReadComplete;
import io.netty.channel.socket.ChannelOutputShutdownEvent;
import io.netty.channel.socket.DuplexChannel;
import io.netty.channel.socket.oio.OioSocketChannel;
import io.netty.util.UncheckedBooleanSupplier;
import io.netty.util.internal.PlatformDependent;
import org.junit.Test;
import java.util.concurrent.CountDownLatch;
@ -414,19 +416,26 @@ public class SocketHalfClosedTest extends AbstractSocketTest {
@Override
public void channelInactive(ChannelHandlerContext ctx) {
checkPrematureClose();
checkPrematureClose(ctx);
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
ctx.close();
checkPrematureClose();
checkPrematureClose(ctx);
}
private void checkPrematureClose() {
private void checkPrematureClose(ChannelHandlerContext ctx) {
if (bytesRead < expectedBytes || !seenOutputShutdown) {
causeRef.set(new IllegalStateException("leader premature close"));
doneLatch.countDown();
if (ctx.channel() instanceof OioSocketChannel && seenOutputShutdown
&& PlatformDependent.javaVersion() >= 11) {
// If we are using OIO and are using Java11 this is expected atm.
// See http://mail.openjdk.java.net/pipermail/net-dev/2018-May/011511.html.
doneLatch.countDown();
} else {
causeRef.set(new IllegalStateException("leader premature close"));
doneLatch.countDown();
}
}
}
}