ruanwenjun commented on issue #482:
URL: https://github.com/apache/mina-sshd/issues/482#issuecomment-2153752493

   @coderZoe @tomaswolf Hi, I meet a problem related to the ssh keepalive.
   My task failed seems due to the ssh channel closed, I am not sure if this is 
due to the heartbeat miss.
   
   ```
   
exceptionCaught(ClientSessionImpl[cebwmapp@/10.227.23.69:16022])[state=Opened] 
IOException: Connection reset by peer
   ```
   
   My code is look like below
   ```
   SshClient sshClient = SshClient.setUpDefaultClient();
   sshClient.start();
   
   ClientSession session = sshClient.connect(
                       sshConnectionParam.getUsername(),
                       sshConnectionParam.getHost(),
                       
sshConnectionParam.getPort()).verify(timeout).getSession();
   String password = sshConnectionParam.getPassword();
   if (StringUtils.isNotEmpty(password)) {
       session.addPasswordIdentity(password);
   }
   String privateKey = sshConnectionParam.getPrivateKey();
   if (StringUtils.isNotEmpty(privateKey)) {
       KeyPairResourceLoader loader = SecurityUtils.getKeyPairResourceParser();
       Collection<KeyPair> keyPairCollection = loader.loadKeyPairs(null, null, 
null, privateKey);
       for (KeyPair keyPair : keyPairCollection) {
           session.addPublicKeyIdentity(keyPair);
       }
   }
   if (!session.auth().verify(Duration.ofSeconds(timeout)).isSuccess()) {
       throw new RuntimeException("Session auth failed");
   }
   session.setSessionHeartbeat(SessionHeartbeatController.HeartbeatType.IGNORE,
           
Duration.ofSeconds(PropertyUtils.getInt("session-connection-heartbeat-interval",
 5)));
   return session;
   ```
   
   Do I need to add KeepAliveHandler.INSTANCE in globalRequestHandlers to avoid 
this?
   
   
   


-- 
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

Reply via email to