From 242890899eca8f240ba26c9f8c6020fceb6847f5 Mon Sep 17 00:00:00 2001 From: Josef Grieb Date: Mon, 31 Aug 2020 06:39:02 +0200 Subject: [PATCH] Fixed segmentation fault error in IovecArrayPool Motivation: segmentation is caused in IovecArrayPool.release because the default of iovecMemoryAddress is 0 Modification: -set default to -1 -some cleanups -added new testsuite tests Result: fixed segmentation error --- .../transport/socket/SocketEchoTest.java | 106 +++++++++--------- .../channel/uring/AbstractIOUringChannel.java | 4 +- .../uring/IOUringRecvByteAllocatorHandle.java | 6 - .../netty/channel/uring/IovecArrayPool.java | 9 +- .../uring/IOUringSocketObjectEchoTest.java | 30 +++++ .../uring/IOUringSocketStringEchoTest.java | 31 +++++ 6 files changed, 117 insertions(+), 69 deletions(-) create mode 100644 transport-native-io_uring/src/test/java/io/netty/channel/uring/IOUringSocketObjectEchoTest.java create mode 100644 transport-native-io_uring/src/test/java/io/netty/channel/uring/IOUringSocketStringEchoTest.java diff --git a/testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketEchoTest.java b/testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketEchoTest.java index 9a63f57629..4d9321b608 100644 --- a/testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketEchoTest.java +++ b/testsuite/src/main/java/io/netty/testsuite/transport/socket/SocketEchoTest.java @@ -67,59 +67,59 @@ public class SocketEchoTest extends AbstractSocketTest { testSimpleEcho0(sb, cb, false, false, true); } -// @Test(timeout = 30000) -// public void testSimpleEchoNotAutoRead() throws Throwable { -// run(); -// } -// -// public void testSimpleEchoNotAutoRead(ServerBootstrap sb, Bootstrap cb) throws Throwable { -// testSimpleEcho0(sb, cb, false, false, false); -// } -// -// @Test//(timeout = 30000) -// public void testSimpleEchoWithAdditionalExecutor() throws Throwable { -// run(); -// } -// -// public void testSimpleEchoWithAdditionalExecutor(ServerBootstrap sb, Bootstrap cb) throws Throwable { -// testSimpleEcho0(sb, cb, true, false, true); -// } -// -// @Test//(timeout = 30000) -// public void testSimpleEchoWithAdditionalExecutorNotAutoRead() throws Throwable { -// run(); -// } -// -// public void testSimpleEchoWithAdditionalExecutorNotAutoRead(ServerBootstrap sb, Bootstrap cb) throws Throwable { -// testSimpleEcho0(sb, cb, true, false, false); -// } -// -// @Test//(timeout = 30000) -// public void testSimpleEchoWithVoidPromise() throws Throwable { -// run(); -// } -// -// public void testSimpleEchoWithVoidPromise(ServerBootstrap sb, Bootstrap cb) throws Throwable { -// testSimpleEcho0(sb, cb, false, true, true); -// } -// -// @Test//(timeout = 30000) -// public void testSimpleEchoWithVoidPromiseNotAutoRead() throws Throwable { -// run(); -// } -// -// public void testSimpleEchoWithVoidPromiseNotAutoRead(ServerBootstrap sb, Bootstrap cb) throws Throwable { -// testSimpleEcho0(sb, cb, false, true, false); -// } -// -// @Test(timeout = 30000) -// public void testSimpleEchoWithAdditionalExecutorAndVoidPromise() throws Throwable { -// run(); -// } -// -// public void testSimpleEchoWithAdditionalExecutorAndVoidPromise(ServerBootstrap sb, Bootstrap cb) throws Throwable { -// testSimpleEcho0(sb, cb, true, true, true); -// } + @Test(timeout = 30000) + public void testSimpleEchoNotAutoRead() throws Throwable { + run(); + } + + public void testSimpleEchoNotAutoRead(ServerBootstrap sb, Bootstrap cb) throws Throwable { + testSimpleEcho0(sb, cb, false, false, false); + } + + @Test//(timeout = 30000) + public void testSimpleEchoWithAdditionalExecutor() throws Throwable { + run(); + } + + public void testSimpleEchoWithAdditionalExecutor(ServerBootstrap sb, Bootstrap cb) throws Throwable { + testSimpleEcho0(sb, cb, true, false, true); + } + + @Test//(timeout = 30000) + public void testSimpleEchoWithAdditionalExecutorNotAutoRead() throws Throwable { + run(); + } + + public void testSimpleEchoWithAdditionalExecutorNotAutoRead(ServerBootstrap sb, Bootstrap cb) throws Throwable { + testSimpleEcho0(sb, cb, true, false, false); + } + + @Test//(timeout = 30000) + public void testSimpleEchoWithVoidPromise() throws Throwable { + run(); + } + + public void testSimpleEchoWithVoidPromise(ServerBootstrap sb, Bootstrap cb) throws Throwable { + testSimpleEcho0(sb, cb, false, true, true); + } + + @Test//(timeout = 30000) + public void testSimpleEchoWithVoidPromiseNotAutoRead() throws Throwable { + run(); + } + + public void testSimpleEchoWithVoidPromiseNotAutoRead(ServerBootstrap sb, Bootstrap cb) throws Throwable { + testSimpleEcho0(sb, cb, false, true, false); + } + + @Test(timeout = 30000) + public void testSimpleEchoWithAdditionalExecutorAndVoidPromise() throws Throwable { + run(); + } + + public void testSimpleEchoWithAdditionalExecutorAndVoidPromise(ServerBootstrap sb, Bootstrap cb) throws Throwable { + testSimpleEcho0(sb, cb, true, true, true); + } private static void testSimpleEcho0( ServerBootstrap sb, Bootstrap cb, boolean additionalExecutor, boolean voidPromise, boolean autoRead) diff --git a/transport-native-io_uring/src/main/java/io/netty/channel/uring/AbstractIOUringChannel.java b/transport-native-io_uring/src/main/java/io/netty/channel/uring/AbstractIOUringChannel.java index 58a177f26b..35020005a1 100644 --- a/transport-native-io_uring/src/main/java/io/netty/channel/uring/AbstractIOUringChannel.java +++ b/transport-native-io_uring/src/main/java/io/netty/channel/uring/AbstractIOUringChannel.java @@ -82,7 +82,7 @@ abstract class AbstractIOUringChannel extends AbstractChannel implements UnixCha private volatile SocketAddress remote; //to release it - private long iovecMemoryAddress; + private long iovecMemoryAddress = -1; AbstractIOUringChannel(final Channel parent, LinuxSocket socket) { super(parent); @@ -274,8 +274,6 @@ abstract class AbstractIOUringChannel extends AbstractChannel implements UnixCha int msgCount = in.size(); if (msgCount > 1 && in.current() instanceof ByteBuf) { doWriteMultiple(in); - //Object msg = in.current(); - //doWriteSingle((ByteBuf) msg); } else if (msgCount == 1) { Object msg = in.current(); doWriteSingle((ByteBuf) msg); diff --git a/transport-native-io_uring/src/main/java/io/netty/channel/uring/IOUringRecvByteAllocatorHandle.java b/transport-native-io_uring/src/main/java/io/netty/channel/uring/IOUringRecvByteAllocatorHandle.java index 528225aeff..f1a116bd8b 100644 --- a/transport-native-io_uring/src/main/java/io/netty/channel/uring/IOUringRecvByteAllocatorHandle.java +++ b/transport-native-io_uring/src/main/java/io/netty/channel/uring/IOUringRecvByteAllocatorHandle.java @@ -25,12 +25,6 @@ final class IOUringRecvByteAllocatorHandle extends RecvByteBufAllocator.Delegati implements RecvByteBufAllocator.ExtendedHandle { private final PreferredDirectByteBufAllocator preferredDirectByteBufAllocator = new PreferredDirectByteBufAllocator(); - private final UncheckedBooleanSupplier defaultMaybeMoreDataSupplier = new UncheckedBooleanSupplier() { - @Override - public boolean get() { - return true; - } - }; IOUringRecvByteAllocatorHandle(RecvByteBufAllocator.ExtendedHandle handle) { super(handle); diff --git a/transport-native-io_uring/src/main/java/io/netty/channel/uring/IovecArrayPool.java b/transport-native-io_uring/src/main/java/io/netty/channel/uring/IovecArrayPool.java index 576f681c39..9f704afcf0 100644 --- a/transport-native-io_uring/src/main/java/io/netty/channel/uring/IovecArrayPool.java +++ b/transport-native-io_uring/src/main/java/io/netty/channel/uring/IovecArrayPool.java @@ -19,7 +19,7 @@ final class IovecArrayPool implements MessageProcessor { private static int poolSize = 40; //Todo IOVEC entries shoule be lower IOVEMAX - private static final int IOV_ENTRIES = 500; + private static final int IOV_ENTRIES = 1024; private static final int IOVEC_ARRAY_SIZE = IOV_SIZE * IOV_ENTRIES; private static final int CAPACITY = IOVEC_ARRAY_SIZE * poolSize; @@ -60,6 +60,7 @@ final class IovecArrayPool implements MessageProcessor { long index = remainingIovec.pop(); currentIovecMemoryAddress = index * IOVEC_ARRAY_SIZE + iovecArrayMemoryAddress; + return currentIovecMemoryAddress; } @@ -124,12 +125,6 @@ final class IovecArrayPool implements MessageProcessor { PlatformDependent.putLong(baseOffset + currentIovecMemoryAddress, addr); PlatformDependent.putLong(lengthOffset + currentIovecMemoryAddress, len); } - } else { - assert ADDRESS_SIZE == 4; - if (PlatformDependent.hasUnsafe()) { - PlatformDependent.putInt(baseOffset + currentIovecMemoryAddress, (int) addr); - PlatformDependent.putInt(lengthOffset + currentIovecMemoryAddress, len); - } } return true; } diff --git a/transport-native-io_uring/src/test/java/io/netty/channel/uring/IOUringSocketObjectEchoTest.java b/transport-native-io_uring/src/test/java/io/netty/channel/uring/IOUringSocketObjectEchoTest.java new file mode 100644 index 0000000000..1cbaab17b1 --- /dev/null +++ b/transport-native-io_uring/src/test/java/io/netty/channel/uring/IOUringSocketObjectEchoTest.java @@ -0,0 +1,30 @@ +/* + * Copyright 2020 The Netty Project + * + * The Netty Project licenses this file to you under the Apache License, + * version 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ +package io.netty.channel.uring; + +import io.netty.bootstrap.Bootstrap; +import io.netty.bootstrap.ServerBootstrap; +import io.netty.testsuite.transport.TestsuitePermutation; +import io.netty.testsuite.transport.socket.SocketObjectEchoTest; + +import java.util.List; + +public class IOUringSocketObjectEchoTest extends SocketObjectEchoTest { + @Override + protected List> newFactories() { + return IOUringSocketTestPermutation.INSTANCE.socket(); + } +} diff --git a/transport-native-io_uring/src/test/java/io/netty/channel/uring/IOUringSocketStringEchoTest.java b/transport-native-io_uring/src/test/java/io/netty/channel/uring/IOUringSocketStringEchoTest.java new file mode 100644 index 0000000000..4b2a37a92a --- /dev/null +++ b/transport-native-io_uring/src/test/java/io/netty/channel/uring/IOUringSocketStringEchoTest.java @@ -0,0 +1,31 @@ +/* + * Copyright 2020 The Netty Project + * + * The Netty Project licenses this file to you under the Apache License, + * version 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ +package io.netty.channel.uring; + +import io.netty.bootstrap.Bootstrap; +import io.netty.bootstrap.ServerBootstrap; +import io.netty.testsuite.transport.TestsuitePermutation; +import io.netty.testsuite.transport.socket.SocketStringEchoTest; + +import java.util.List; + +public class IOUringSocketStringEchoTest extends SocketStringEchoTest { + + @Override + protected List> newFactories() { + return IOUringSocketTestPermutation.INSTANCE.socket(); + } +}