From d512058bc228950fab6ede804c0b533588367dcf Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Fri, 31 Jul 2020 10:38:30 +0200 Subject: [PATCH] Enable server heartbeats 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 --- .../netconf/ssh/SshProxyServer.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/netconf/mdsal-netconf-ssh/src/main/java/org/opendaylight/netconf/ssh/SshProxyServer.java b/netconf/mdsal-netconf-ssh/src/main/java/org/opendaylight/netconf/ssh/SshProxyServer.java index b294da39b5..785a519ff5 100644 --- a/netconf/mdsal-netconf-ssh/src/main/java/org/opendaylight/netconf/ssh/SshProxyServer.java +++ b/netconf/mdsal-netconf-ssh/src/main/java/org/opendaylight/netconf/ssh/SshProxyServer.java @@ -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, -- 2.36.6