Skip to content

Commit

Permalink
Fix test-failure on macOS with JDK versions < 20 (netty#12597)
Browse files Browse the repository at this point in the history
Motivation:

Calling DatagramChannel.disconnect() on JDK versions < 20 with mapped ipv6 addresses throw an exception, we should workaround this bug.

Modifications:

Only try to call disconnect() when the DatagramChannel is not using NIO when using mapped ipv6 addresses

Result:

No more build failures on macOS
  • Loading branch information
normanmaurer authored Jul 12, 2022
1 parent c05287c commit 73ef1f8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
*/
package io.netty.testsuite.transport.socket;

import io.netty.channel.socket.DatagramChannel;
import io.netty.channel.socket.nio.NioDatagramChannel;
import io.netty.util.NetUtil;
import io.netty.util.internal.PlatformDependent;

import java.net.InetAddress;
import java.net.InetSocketAddress;
Expand All @@ -36,4 +39,13 @@ protected InetSocketAddress sendToAddress(InetSocketAddress serverAddress) {
}
return serverAddress;
}

@Override
protected boolean disconnectMightFail(DatagramChannel channel) {
// See https://bugs.openjdk.org/browse/JDK-8285515
if (channel instanceof NioDatagramChannel && PlatformDependent.javaVersion() < 20) {
return true;
}
return super.disconnectMightFail(channel);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelOption;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.channel.socket.DatagramChannel;
import io.netty.util.NetUtil;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
Expand All @@ -32,6 +33,7 @@
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.net.SocketException;
import java.nio.channels.NotYetConnectedException;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -302,8 +304,17 @@ private void testSimpleSendWithConnect0(Bootstrap sb, Bootstrap cb, ByteBuf buf,
assertNotNull(cc.remoteAddress());

if (supportDisconnect()) {
// Test what happens when we call disconnect()
cc.disconnect().syncUninterruptibly();
try {
// Test what happens when we call disconnect()
cc.disconnect().syncUninterruptibly();
} catch (Throwable e) {
if (e instanceof SocketException) {
if (disconnectMightFail((DatagramChannel) cc)) {
return;
}
}
throw e;
}
assertFalse(isConnected(cc));
assertNotNull(cc.localAddress());
assertNull(cc.remoteAddress());
Expand Down Expand Up @@ -348,6 +359,10 @@ protected abstract Channel setupServerChannel(Bootstrap sb, byte[] bytes, Socket

protected abstract boolean supportDisconnect();

protected boolean disconnectMightFail(DatagramChannel channel) {
return false;
}

protected abstract ChannelFuture write(Channel cc, ByteBuf buf, SocketAddress remote, WrapType wrapType);

protected static void closeChannel(Channel channel) throws Exception {
Expand Down

0 comments on commit 73ef1f8

Please sign in to comment.