Enable server heartbeats 88/91788/5
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 31 Jul 2020 08:38:30 +0000 (10:38 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 26 Aug 2020 15:27:12 +0000 (17:27 +0200)
When we configure the server to have any timeout, make sure we give
initiate a heartbeat at least three times before timing out. Also, if
we do not specify the idle timer, we need to disable NIO2 read timeout.

JIRA: NETCONF-716
Change-Id: I2c6ed07b5d3b29f6524b0ed99067895c4dfdc020
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
netconf/mdsal-netconf-ssh/src/main/java/org/opendaylight/netconf/ssh/SshProxyServer.java

index b294da39b545381af8fed361f4fa856469788ca9..785a519ff5edae80bf016dc0fd72c969b44b1424 100644 (file)
@@ -33,8 +33,8 @@ import org.opendaylight.netconf.shaded.sshd.common.io.IoServiceFactoryFactory;
 import org.opendaylight.netconf.shaded.sshd.common.io.nio2.Nio2Acceptor;
 import org.opendaylight.netconf.shaded.sshd.common.io.nio2.Nio2Connector;
 import org.opendaylight.netconf.shaded.sshd.common.io.nio2.Nio2ServiceFactoryFactory;
+import org.opendaylight.netconf.shaded.sshd.common.session.SessionHeartbeatController.HeartbeatType;
 import org.opendaylight.netconf.shaded.sshd.common.util.closeable.AbstractCloseable;
-import org.opendaylight.netconf.shaded.sshd.server.ServerFactoryManager;
 import org.opendaylight.netconf.shaded.sshd.server.SshServer;
 
 /**
@@ -89,10 +89,19 @@ public class SshProxyServer implements AutoCloseable {
 
         sshServer.setIoServiceFactoryFactory(nioServiceWithPoolFactoryFactory);
         sshServer.setScheduledExecutorService(minaTimerExecutor);
-        sshServer.getProperties().put(ServerFactoryManager.IDLE_TIMEOUT,
-            String.valueOf(sshProxyServerConfiguration.getIdleTimeout()));
-        sshServer.getProperties().put(ServerFactoryManager.AUTH_TIMEOUT,
-            String.valueOf(sshProxyServerConfiguration.getIdleTimeout()));
+
+        final int idleTimeout = sshProxyServerConfiguration.getIdleTimeout();
+        sshServer.getProperties().put(FactoryManager.IDLE_TIMEOUT, String.valueOf(idleTimeout));
+        final String nioReadTimeout;
+        if (idleTimeout > 0) {
+            final long heartBeat = idleTimeout * 333333L;
+            sshServer.setSessionHeartbeat(HeartbeatType.IGNORE, TimeUnit.NANOSECONDS, heartBeat);
+            nioReadTimeout = String.valueOf(idleTimeout + TimeUnit.SECONDS.toMillis(15L));
+        } else {
+            nioReadTimeout = "0";
+        }
+        sshServer.getProperties().put(FactoryManager.NIO2_READ_TIMEOUT, nioReadTimeout);
+        sshServer.getProperties().put(FactoryManager.AUTH_TIMEOUT, String.valueOf(idleTimeout));
 
         final RemoteNetconfCommand.NetconfCommandFactory netconfCommandFactory =
                 new RemoteNetconfCommand.NetconfCommandFactory(clientGroup,