tomaswolf commented on code in PR #507: URL: https://github.com/apache/mina-sshd/pull/507#discussion_r1617834382
########## sshd-core/src/main/java/org/apache/sshd/client/session/ClientConnectionService.java: ########## @@ -55,7 +61,40 @@ public ClientConnectionService(AbstractClientSession s) throws SshException { heartbeatRequest = CoreModuleProperties.HEARTBEAT_REQUEST.getRequired(this); heartbeatInterval = CoreModuleProperties.HEARTBEAT_INTERVAL.getRequired(this); - heartbeatReplyMaxWait = CoreModuleProperties.HEARTBEAT_REPLY_WAIT.getRequired(this); + heartbeatMaxNoReply = configureMaxNoReply(); + } + + protected int configureMaxNoReply() { + @SuppressWarnings("deprecation") + Duration timeout = CoreModuleProperties.HEARTBEAT_REPLY_WAIT.getOrNull(this); + if (timeout == null || GenericUtils.isNegativeOrNull(heartbeatInterval) || GenericUtils.isEmpty(heartbeatRequest)) { + return CoreModuleProperties.HEARTBEAT_NO_REPLY_MAX.getRequired(this).intValue(); + } + // The deprecated timeout is configured explicitly. If the new no reply max is _not_ explicitly configured, + // set it from the timeout. + Integer noReplyValue = CoreModuleProperties.HEARTBEAT_NO_REPLY_MAX.getOrNull(this); + if (noReplyValue != null) { + return noReplyValue.intValue(); + } + if (timeout.compareTo(heartbeatInterval) >= 0) { + // Timeout is longer than the interval. With the old system, that would have killed the session when the + // timeout was reached. A slow server that managed to return the reply just before the timeout expired would + // have delayed subsequent heartbeats. The new system will keep sending heartbeats with the given interval. + // Thus we can have timeout / interval heartbeats without reply if we want to approximate the old system. + double timeoutSec = timeout.getSeconds() + (timeout.getNano() / 1_000_000_000.0); + double intervalSec = heartbeatInterval.getSeconds() + (heartbeatInterval.getNano() / 1_000_000_000.0); + double multiple = timeoutSec / intervalSec; + if (multiple >= Integer.MAX_VALUE - 1) { + return Integer.MAX_VALUE; + } else { + return (int) multiple + 1; + } + } + // Timeout is smaller than the interval. We want to have every heartbeat replied to. + return 1; + // This is an approximation. If no reply is forthcoming, the session will newly be killed after the interval. In Review Comment: Done. ########## sshd-core/src/main/java/org/apache/sshd/client/session/ClientConnectionService.java: ########## @@ -55,7 +61,40 @@ public ClientConnectionService(AbstractClientSession s) throws SshException { heartbeatRequest = CoreModuleProperties.HEARTBEAT_REQUEST.getRequired(this); heartbeatInterval = CoreModuleProperties.HEARTBEAT_INTERVAL.getRequired(this); - heartbeatReplyMaxWait = CoreModuleProperties.HEARTBEAT_REPLY_WAIT.getRequired(this); + heartbeatMaxNoReply = configureMaxNoReply(); + } + + protected int configureMaxNoReply() { + @SuppressWarnings("deprecation") + Duration timeout = CoreModuleProperties.HEARTBEAT_REPLY_WAIT.getOrNull(this); + if (timeout == null || GenericUtils.isNegativeOrNull(heartbeatInterval) || GenericUtils.isEmpty(heartbeatRequest)) { + return CoreModuleProperties.HEARTBEAT_NO_REPLY_MAX.getRequired(this).intValue(); + } + // The deprecated timeout is configured explicitly. If the new no reply max is _not_ explicitly configured, + // set it from the timeout. + Integer noReplyValue = CoreModuleProperties.HEARTBEAT_NO_REPLY_MAX.getOrNull(this); + if (noReplyValue != null) { + return noReplyValue.intValue(); + } + if (timeout.compareTo(heartbeatInterval) >= 0) { + // Timeout is longer than the interval. With the old system, that would have killed the session when the Review Comment: Done. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@mina.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@mina.apache.org For additional commands, e-mail: dev-h...@mina.apache.org