From 69e38fc52cef8facd54086a5b8e5d5ca0dab5173 Mon Sep 17 00:00:00 2001 From: leventov Date: Fri, 9 Oct 2015 15:15:35 +0300 Subject: [PATCH] Fix a bug in TcpReplicator -- didn't schedule to connect to an endpoint later, when channel.socket().setTcpNoDelay(true) throws an exception --- .../openhft/chronicle/map/TcpReplicator.java | 40 +++++++++++-------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/src/main/java/net/openhft/chronicle/map/TcpReplicator.java b/src/main/java/net/openhft/chronicle/map/TcpReplicator.java index 119491828..2f8803f37 100644 --- a/src/main/java/net/openhft/chronicle/map/TcpReplicator.java +++ b/src/main/java/net/openhft/chronicle/map/TcpReplicator.java @@ -451,7 +451,12 @@ final class TcpReplicator extends AbstractChannelReplicator implements Clo if (!channel.finishConnect()) { return; } - } catch (SocketException e) { + + channel.configureBlocking(false); + channel.socket().setTcpNoDelay(true); + channel.socket().setSoTimeout(0); + channel.socket().setSoLinger(false, 0); + } catch (IOException e) { quietClose(key, e); // when node discovery is used ( by nodes broadcasting out their host:port over UDP ), @@ -473,11 +478,6 @@ final class TcpReplicator extends AbstractChannelReplicator implements Clo LOG.debug("successfully connected to {}, local-id={}", channel.socket().getInetAddress(), localIdentifier); - channel.configureBlocking(false); - channel.socket().setTcpNoDelay(true); - channel.socket().setSoTimeout(0); - channel.socket().setSoLinger(false, 0); - attached.entryReader = new TcpSocketChannelEntryReader(); attached.entryWriter = new TcpSocketChannelEntryWriter(); @@ -1028,6 +1028,7 @@ final class TcpReplicator extends AbstractChannelReplicator implements Clo } catch (ClosedChannelException e) { if (socketChannel.isOpen()) LOG.error("", e); + onFail(socketChannel); } } }); @@ -1037,20 +1038,25 @@ final class TcpReplicator extends AbstractChannelReplicator implements Clo return socketChannel; } finally { if (!success) { - try { - try { - socketChannel.socket().close(); - } catch (Exception e) { - LOG.error("", e); - } - socketChannel.close(); - } catch (IOException e) { - LOG.error("", e); - } - this.connectLater(); + onFail(socketChannel); } } } + + private void onFail(SocketChannel socketChannel) { + try { + try { + socketChannel.socket().close(); + } catch (Exception e) { + LOG.error("", e); + } + socketChannel.close(); + } catch (IOException e) { + LOG.error("", e); + } finally { + this.connectLater(); + } + } } /**