Repository: ignite Updated Branches: refs/heads/master d67c5bf4c -> 92fae6006
IGNITE-8683 Fixed corner case failing after IGNITE-6639 fix - Fixes #4109. Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/92fae600 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/92fae600 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/92fae600 Branch: refs/heads/master Commit: 92fae6006c6f05c2696b8980243e4c41fb554cdd Parents: d67c5bf Author: mcherkasov <[email protected]> Authored: Mon Jul 16 19:09:49 2018 +0300 Committer: Alexey Goncharuk <[email protected]> Committed: Mon Jul 16 19:09:49 2018 +0300 ---------------------------------------------------------------------- .../ignite/internal/util/IgniteUtils.java | 20 ++++++++++++++++++++ .../communication/tcp/TcpCommunicationSpi.java | 16 +++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/92fae600/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java index 62d1117..b336f91 100755 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java @@ -2226,6 +2226,26 @@ public abstract class IgniteUtils { } /** + * Checks if the address is local. + * + * @param addr Address for check. + * @return true if address is local, otherwise false + */ + public static boolean isLocalAddress(InetAddress addr) { + // Check if the address is a valid special local or loop back + if (addr.isAnyLocalAddress() || addr.isLoopbackAddress()) + return true; + + // Check if the address is defined on any interface + try { + return NetworkInterface.getByInetAddress(addr) != null; + } + catch (SocketException e) { + return false; + } + } + + /** * Gets a list of all local enabled MACs known to this JVM. It * is using hardware address of the network interface that is not guaranteed to be * MAC addresses (but in most cases it is). http://git-wip-us.apache.org/repos/asf/ignite/blob/92fae600/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java b/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java index 3eab09b..91250c9 100755 --- a/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java +++ b/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java @@ -3230,7 +3230,7 @@ public class TcpCommunicationSpi extends IgniteSpiAdapter implements Communicati if (stopping) throw new IgniteSpiException("Node is stopping."); - if (addr.getAddress().isLoopbackAddress() && addr.getPort() == boundTcpPort) { + if (isLocalNodeAddress(addr)) { if (log.isDebugEnabled()) log.debug("Skipping local address [addr=" + addr + ", locAddrs=" + node.attribute(createSpiAttributeName(ATTR_ADDRS)) + @@ -3476,6 +3476,20 @@ public class TcpCommunicationSpi extends IgniteSpiAdapter implements Communicati } /** + * Check is passed socket address belong to current node. This method should return true only if the passed + * in address represent an address which will result in a connection to the local node. + * + * @param addr address to check. + * @return true if passed address belongs to local node, otherwise false. + */ + private boolean isLocalNodeAddress(InetSocketAddress addr) { + return addr.getPort() == boundTcpPort + && (locHost.equals(addr.getAddress()) + || addr.getAddress().isAnyLocalAddress() + || (locHost.isAnyLocalAddress() && U.isLocalAddress(addr.getAddress()))); + } + + /** * Process errors if TCP client to remote node hasn't been created. * * @param node Remote node.
