From cd9aafbe2bc803847a3c3eda2c6b61f1f81719c7 Mon Sep 17 00:00:00 2001 From: Rob Austin Date: Mon, 14 Sep 2015 15:16:37 +0100 Subject: [PATCH] fixed issue with --- .../openhft/chronicle/map/TcpReplicator.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/main/java/net/openhft/chronicle/map/TcpReplicator.java b/src/main/java/net/openhft/chronicle/map/TcpReplicator.java index 3547157b0..38d152d0c 100644 --- a/src/main/java/net/openhft/chronicle/map/TcpReplicator.java +++ b/src/main/java/net/openhft/chronicle/map/TcpReplicator.java @@ -359,8 +359,7 @@ public final class TcpReplicator extends AbstractChannelReplicator impleme final Attached attached = (Attached) key.attachment(); - // we wont attempt to reconnect the server socket - if (attached.isServer || !attached.isHandShakingComplete()) + if (attached.isServer && !attached.isHandShakingComplete()) return; final SocketChannel channel = (SocketChannel) key.channel(); @@ -371,6 +370,8 @@ public final class TcpReplicator extends AbstractChannelReplicator impleme LOG.debug("lost connection, attempting to reconnect. " + "missed heartbeat from identifier=" + attached.remoteIdentifier); activeKeys.clear(attached.remoteIdentifier); + quietClose(key, null); + closeables.closeQuietly(channel.socket()); // when node discovery is used ( by nodes broadcasting out their host:port over UDP ), @@ -390,8 +391,8 @@ public final class TcpReplicator extends AbstractChannelReplicator impleme * @param key the SelectionKey * @param e the Exception that caused the issue */ - private void quietClose(@NotNull final SelectionKey key, @NotNull final Exception e) { - if (LOG.isDebugEnabled()) + private void quietClose(@NotNull final SelectionKey key, @Nullable final Exception e) { + if (LOG.isDebugEnabled() && e != null) LOG.debug("", e); if (key.channel() != null && key.attachment() != null && connectionListener != null) @@ -589,8 +590,10 @@ public final class TcpReplicator extends AbstractChannelReplicator impleme final SocketChannel channel = (SocketChannel) key.channel(); if (channel != null && channel.socket() != null && connectionListener != null) { - connectionListener.onConnect(channel.socket().getInetAddress(), - attached.remoteIdentifier, attached.isServer); + connectionListener.onConnect( + channel.socket().getInetAddress(), + attached.remoteIdentifier, + attached.isServer); } // we use the as iterating the activeKeys via the bitset wont create and Objects @@ -786,7 +789,7 @@ public final class TcpReplicator extends AbstractChannelReplicator impleme int len = attached.entryReader.readSocketToBuffer(socketChannel); if (len == -1) { - socketChannel.register(selector, 0); + socketChannel.register(selector, 0, attached); if (replicationConfig.autoReconnectedUponDroppedConnection()) { AbstractConnector connector = attached.connector; if (connector != null)