[ https://issues.apache.org/jira/browse/SSHD-781?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16223336#comment-16223336 ]
MayDay edited comment on SSHD-781 at 10/28/17 8:53 AM: ------------------------------------------------------- {quote}I am not sure I understand exactly what you are trying to accomplish and why this heartbeat issue with the wantReply=true is so crucial so I don't feel I can give you an exact answer{quote} The reason why I want to set the wantReply of heartbeat true is: If the sshServer is not implemented by MINA-SSHD,like OpenSSH, I create a Client implemented by MINA-SSHD to connect to a Server implemented by openSSH, I hope the heartbeat can work the same way. If set the wantReply of heartbeat true, Any server that follows the SSH protocol will response the heartbeat of our client(even though SSH_MSG_FAILED).In normal circumstances,the client send heartbeat periodly and read the reponse from server to reset the read timeout. When the network between client and server become unavailable,the client will throw a exception after the read timeout and close the session. [~lgoldstein]Thanks for your advice I hope this explanation will help you understand my intentions,just want the client keepalive can be compatible better with server implemented in different languages As the [SSHD-782|https://issues.apache.org/jira/browse/SSHD-782], create a mechanism to send a periodic server-side SSH_MSG_IGNORE messages to client,then the client use the SSH_MSG_IGNORE messages to reset read timeout is also a means to make client keepalive. was (Author: mayday): {quote}I am not sure I understand exactly what you are trying to accomplish and why this heartbeat issue with the wantReply=true is so crucial so I don't feel I can give you an exact answer{quote} The reason why I want to set the wantReply of heartbeat true is: If the sshServer is not implemented by MINA-SSHD,like OpenSSH, I create a Client implemented by MINA-SSHD to connect to a Server implemented by openSSH, I hope the heartbeat can work the same way. If set the wantReply of heartbeat true, Any server that follows the SSH protocol will response the heartbeat of our client(even though SSH_MSG_FAILED).In normal circumstances,the client send heartbeat periodly and read the reponse from server to reset the read timeout. When the network between client and server become unavailable,the client will throw a exception after the read timeout and close the session. I hope this explanation will help you understand my intentions,just want the client keepalive can be compatible better with server implemented in different languages As the [SSHD-782|https://issues.apache.org/jira/browse/SSHD-782], create a mechanism to send a periodic server-side SSH_MSG_IGNORE messages to client,then the client use the SSH_MSG_IGNORE messages to reset read timeout is also a means to make client keepalive. > The heartbeat task of client not support keepalive function well > ---------------------------------------------------------------- > > Key: SSHD-781 > URL: https://issues.apache.org/jira/browse/SSHD-781 > Project: MINA SSHD > Issue Type: Question > Affects Versions: 1.4.0, 1.6.0 > Environment: Any environment > Reporter: MayDay > Assignee: Guillaume Nodet > Labels: test > Fix For: 1.7.0 > > > > The heartbeat request of sshClient is a SSH_MSG_GLOBAL_REQUEST, but > the default buffer of heartbeat set false (see > [ClientConnectService#sendHeartbeat|https://github.com/apache/mina-sshd/blob/693fa5d90f54676de6655954046a8a4f5d09728a/sshd-core/src/main/java/org/apache/sshd/client/session/ClientConnectionService.java]) > {code:java} > buf.putBoolean(false); > {code} > The sshServer reponse the heartbeat by the > [KeepAliveHandler|https://github.com/apache/mina-sshd/blob/693fa5d90f54676de6655954046a8a4f5d09728a/sshd-core/src/main/java/org/apache/sshd/server/global/KeepAliveHandler.java], > then [AbstractConnectionService > #sendGlobalResponse|https://github.com/apache/mina-sshd/blob/693fa5d90f54676de6655954046a8a4f5d09728a/sshd-core/src/main/java/org/apache/sshd/common/session/helpers/AbstractConnectionService.java]. > {code:java} > boolean wantReply = buffer.getBoolean(); > {code} > but if the buffer of heartbeat set false, then the sendGlobalResponse > will not reponse sshClient {color:#205081}because of the wantReply is > false{color} .(see [AbstractConnectionService > #globalRequest|https://github.com/apache/mina-sshd/blob/693fa5d90f54676de6655954046a8a4f5d09728a/sshd-core/src/main/java/org/apache/sshd/common/session/helpers/AbstractConnectionService.java]) > {code:java} > if (RequestHandler.Result.Replied.equals(result) || (!wantReply)) { > return new AbstractIoWriteFuture(req, null) { > { > setValue(Boolean.TRUE); > } > }; > } > {code} > 1 、Is it a Bug(set the heartbeat buffer false default)? how the sshClient > know the server is available when the server don't response. > I have test it whth create a client with params ( > HEARTBEAT_INTERAL = 60 > IDLE_TIMEOUT = 300 > NIO_READ_TIMEOUT = 315)and a server, and the client will close seesion after > the NIO_READ_TIMEOUT. > 2、If the client reach the NIO_READ_TIMEOUT, then thows a > {color:#8eb021}InterruptedByTimeoutException{color},and close the session.But > the task of heratbeat not stoped, it will continue to run even though it will > not send packet.See the > [ClientConnectionService > #startHeartBeat|https://github.com/apache/mina-sshd/blob/693fa5d90f54676de6655954046a8a4f5d09728a/sshd-core/src/main/java/org/apache/sshd/client/session/ClientConnectionService.java] > {code:java} > service.scheduleAtFixedRate(this::sendHeartBeat, interval, interval, > TimeUnit.MILLISECONDS); > {code} > if the sshClient reopen a new session and close it many times,the number of > invalid scheduling heartbeat task will become very large, it's not > equitable. > -- This message was sent by Atlassian JIRA (v6.4.14#64029)