Reduce NETCONF device disconnect warnings 14/97214/2
authorRobert Varga <robert.varga@pantheon.tech>
Sat, 14 Aug 2021 12:26:57 +0000 (14:26 +0200)
committerTomas Cere <tomas.cere@pantheon.tech>
Tue, 17 Aug 2021 07:28:04 +0000 (07:28 +0000)
Document java.io.EOFException as the natural end-of-stream cause and
handle that case with less alarm as other causes.

JIRA: NETCONF-805
Change-Id: If3b07125434e2a5faec90b1cd0144dc3d9f6c818
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/NetconfSessionListener.java
netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/AbstractNetconfSession.java
netconf/netconf-netty-util/src/test/java/org/opendaylight/netconf/nettyutil/AbstractNetconfSessionTest.java
netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/listener/NetconfDeviceCommunicator.java

index 6f64fc5b73c4caf828db91922823a4caf558f972..9574c47df5bb50c0f6a7758297f7fa90d5a872cf 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.netconf.api;
 
+import java.io.EOFException;
+
 // FIXME: NETCONF-554: rework this interface
 public interface NetconfSessionListener<S extends NetconfSession> {
     /**
@@ -21,7 +23,8 @@ public interface NetconfSessionListener<S extends NetconfSession> {
      * session.
      *
      * @param session that went down
-     * @param cause Exception that was thrown as the cause of session being down
+     * @param cause Exception that was thrown as the cause of session being down. A common cause is
+     *              {@link EOFException}, which indicates the remote end has shut down the communication channel.
      */
     void onSessionDown(S session, Exception cause);
 
index aab5b6d0c0320ae2e686db53bb3edd7455ceb090..d8c0697ae55f4773fe3328fc89a61df05cd2ecac 100644 (file)
@@ -15,7 +15,7 @@ import io.netty.channel.ChannelPromise;
 import io.netty.channel.SimpleChannelInboundHandler;
 import io.netty.handler.codec.ByteToMessageDecoder;
 import io.netty.handler.codec.MessageToByteEncoder;
-import java.io.IOException;
+import java.io.EOFException;
 import org.opendaylight.netconf.api.NetconfExiSession;
 import org.opendaylight.netconf.api.NetconfMessage;
 import org.opendaylight.netconf.api.NetconfSession;
@@ -31,10 +31,11 @@ import org.opendaylight.netconf.shaded.exificient.core.exceptions.UnsupportedOpt
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public abstract class AbstractNetconfSession<S extends NetconfSession,L extends NetconfSessionListener<S>>
+public abstract class AbstractNetconfSession<S extends NetconfSession, L extends NetconfSessionListener<S>>
         extends SimpleChannelInboundHandler<Object> implements NetconfSession, NetconfExiSession {
-
     private static final Logger LOG = LoggerFactory.getLogger(AbstractNetconfSession.class);
+
+
     private final L sessionListener;
     private final long sessionId;
     private boolean up = false;
@@ -88,11 +89,9 @@ public abstract class AbstractNetconfSession<S extends NetconfSession,L extends
     }
 
     protected void endOfInput() {
-        LOG.debug("Session {} end of input detected while session was in state {}", this, isUp() ? "up"
-                : "initialized");
-        if (isUp()) {
-            this.sessionListener.onSessionDown(thisInstance(),
-                    new IOException("End of input detected. Close the session."));
+        LOG.debug("Session {} end of input detected while session was in state {}", this, up ? "up" : "initialized");
+        if (up) {
+            this.sessionListener.onSessionDown(thisInstance(), new EOFException("End of input"));
         }
     }
 
index 5cd450edada743eb0e7774769e50b00400039b9d..f4b64cfc4bb7d066b150a9b87b66bf52c95dd53c 100644 (file)
@@ -27,6 +27,7 @@ import io.netty.channel.ChannelPromise;
 import io.netty.channel.EventLoop;
 import io.netty.handler.codec.ByteToMessageDecoder;
 import io.netty.handler.codec.MessageToByteEncoder;
+import java.io.EOFException;
 import java.util.Collections;
 import java.util.Optional;
 import org.junit.Before;
@@ -140,7 +141,7 @@ public class AbstractNetconfSessionTest {
         verifyNoMoreInteractions(listener);
         testingNetconfSession.sessionUp();
         testingNetconfSession.endOfInput();
-        verify(listener).onSessionDown(any(TestingNetconfSession.class), any(Exception.class));
+        verify(listener).onSessionDown(any(TestingNetconfSession.class), any(EOFException.class));
     }
 
     @Test
index b6725d6231c3c6290deef4b37f0f66fee05daa0e..0f358273fb287347f052126e5ed8f20726306c7d 100644 (file)
@@ -11,6 +11,7 @@ import com.google.common.base.Strings;
 import com.google.common.util.concurrent.ListenableFuture;
 import com.google.common.util.concurrent.SettableFuture;
 import io.netty.util.concurrent.Future;
+import java.io.EOFException;
 import java.util.ArrayDeque;
 import java.util.ArrayList;
 import java.util.Iterator;
@@ -235,7 +236,11 @@ public class NetconfDeviceCommunicator
     public void onSessionDown(final NetconfClientSession session, final Exception exception) {
         // If session is already in closing, no need to call tearDown again.
         if (startClosing()) {
-            LOG.warn("{}: Session went down", id, exception);
+            if (exception instanceof EOFException) {
+                LOG.info("{}: Session went down: {}", id, exception.getMessage());
+            } else {
+                LOG.warn("{}: Session went down", id, exception);
+            }
             tearDown(null);
         }
     }