Repository: ignite Updated Branches: refs/heads/ignite-1758 4917cff1d -> e28b876ee
Fixing NIO thread death if communication exception is occurred. Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/473cb9e7 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/473cb9e7 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/473cb9e7 Branch: refs/heads/ignite-1758 Commit: 473cb9e70a2f74561435edbda522d7b5800ac7d2 Parents: ff96888 Author: Alexey Goncharuk <[email protected]> Authored: Tue Oct 20 17:45:02 2015 +0300 Committer: Alexey Goncharuk <[email protected]> Committed: Tue Oct 20 17:45:02 2015 +0300 ---------------------------------------------------------------------- .../ignite/internal/util/nio/GridNioServer.java | 2 +- .../nio/IgniteExceptionInNioWorkerSelfTest.java | 105 +++++++++++++++++++ .../ignite/testsuites/IgniteBasicTestSuite.java | 3 + 3 files changed, 109 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/473cb9e7/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridNioServer.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridNioServer.java b/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridNioServer.java index 82fb1bb..1824339 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridNioServer.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridNioServer.java @@ -1443,7 +1443,7 @@ public class GridNioServer<T> { // This exception will be handled in bodyInternal() method. throw e; } - catch (IOException e) { + catch (Exception e) { if (!closed) U.warn(log, "Failed to process selector key (will close): " + ses, e); http://git-wip-us.apache.org/repos/asf/ignite/blob/473cb9e7/modules/core/src/test/java/org/apache/ignite/internal/util/nio/IgniteExceptionInNioWorkerSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/util/nio/IgniteExceptionInNioWorkerSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/util/nio/IgniteExceptionInNioWorkerSelfTest.java new file mode 100644 index 0000000..9961833 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/util/nio/IgniteExceptionInNioWorkerSelfTest.java @@ -0,0 +1,105 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF 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 org.apache.ignite.internal.util.nio; + +import java.util.UUID; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.internal.GridTopic; +import org.apache.ignite.internal.IgniteKernal; +import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; +import org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi; +import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi; +import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder; +import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; + +/** + * + */ +public class IgniteExceptionInNioWorkerSelfTest extends GridCommonAbstractTest { + /** */ + private static final int GRID_CNT = 4; + + /** */ + private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + CacheConfiguration ccfg = new CacheConfiguration("cache"); + + ccfg.setBackups(1); + + cfg.setCacheConfiguration(ccfg); + + TcpDiscoverySpi discoSpi = new TcpDiscoverySpi(); + + discoSpi.setIpFinder(IP_FINDER); + + TcpCommunicationSpi commSpi = new TcpCommunicationSpi(); + + commSpi.setSharedMemoryPort(-1); + + cfg.setCommunicationSpi(commSpi); + + return cfg; + } + + /** + * @throws Exception If failed. + */ + public void testBrokenMessage() throws Exception { + startGrids(GRID_CNT); + + try { + IgniteKernal kernal = (IgniteKernal)ignite(0); + + UUID nodeId = ignite(1).cluster().localNode().id(); + + // This should trigger a failure in a NIO thread. + kernal.context().io().send(nodeId, GridTopic.TOPIC_CACHE.topic("cache"), new BrokenMessage(), (byte)0); + + for (int i = 0; i < 100; i++) + ignite(0).cache("cache").put(i, i); + } + finally { + stopAllGrids(); + } + } + + /** + * + */ + private static class BrokenMessage extends AffinityTopologyVersion { + /** */ + private boolean fail = true; + + /** {@inheritDoc} */ + @Override public byte directType() { + if (fail) { + fail = false; + + return (byte)242; + } + + return super.directType(); + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/473cb9e7/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java index 1a9913f..0e5894d 100644 --- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java +++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java @@ -41,6 +41,7 @@ import org.apache.ignite.internal.processors.continuous.GridEventConsumeSelfTest import org.apache.ignite.internal.processors.continuous.GridMessageListenSelfTest; import org.apache.ignite.internal.processors.service.ClosureServiceClientsNodesTest; import org.apache.ignite.internal.product.GridProductVersionSelfTest; +import org.apache.ignite.internal.util.nio.IgniteExceptionInNioWorkerSelfTest; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.messaging.GridMessagingNoPeerClassLoadingSelfTest; import org.apache.ignite.messaging.GridMessagingSelfTest; @@ -111,6 +112,8 @@ public class IgniteBasicTestSuite extends TestSuite { suite.addTestSuite(IgniteSlowClientDetectionSelfTest.class); suite.addTestSuite(IgniteDaemonNodeMarshallerCacheTest.class); + suite.addTestSuite(IgniteExceptionInNioWorkerSelfTest.class); + return suite; } } \ No newline at end of file
