From b727493f3092cf5aa741f7ce5f9e82ebc6d098fc Mon Sep 17 00:00:00 2001 From: kexianjun Date: Tue, 8 Jan 2019 14:07:32 +0800 Subject: [PATCH] optimize ReconnectTimerTask's log output (#3162) * optimize log output * Separate logs for reconnect and close * remove reconnect exception log --- .../support/header/ReconnectTimerTask.java | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/support/header/ReconnectTimerTask.java b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/support/header/ReconnectTimerTask.java index dccbe5332cd..2b7dca552c8 100644 --- a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/support/header/ReconnectTimerTask.java +++ b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/support/header/ReconnectTimerTask.java @@ -38,24 +38,26 @@ public class ReconnectTimerTask extends AbstractTimerTask { @Override protected void doTask(Channel channel) { - try { - Long lastRead = lastRead(channel); - Long now = now(); - if (lastRead != null && now - lastRead > heartbeatTimeout) { - logger.warn("Close channel " + channel + ", because heartbeat read idle time out: " - + heartbeatTimeout + "ms"); - if (channel instanceof Client) { - try { - ((Client) channel).reconnect(); - } catch (Exception e) { - //do nothing - } - } else { + Long lastRead = lastRead(channel); + Long now = now(); + if (lastRead != null && now - lastRead > heartbeatTimeout) { + if (channel instanceof Client) { + try { + logger.warn("Reconnect to remote channel " + channel.getRemoteAddress() + ", because heartbeat read idle time out: " + + heartbeatTimeout + "ms"); + ((Client) channel).reconnect(); + } catch (Throwable t) { + // do nothing + } + } else { + try { + logger.warn("Close channel " + channel + ", because heartbeat read idle time out: " + + heartbeatTimeout + "ms"); channel.close(); + } catch (Throwable t) { + logger.warn("Exception when close channel " + channel, t); } } - } catch (Throwable t) { - logger.warn("Exception when reconnect to remote channel " + channel.getRemoteAddress(), t); } } }