vendredi 28 août 2020

ssh request on old conection is giving EOF eventually

I work on agent demon which runs on a node. When we start the agent, all the ssh connections to the other nodes are built and later on at particular time intervals(weekly once) we create new sessions on these ssh connections to communicate with the other nodes. but it has been observed that after 1 month around the time frame, the session creation would give EOF error.

      User: config.Username,
      Auth: []ssh.AuthMethod{
         ssh.Password(config.Password),
      },
      HostKeyCallback: func(hostname string, remote net.Addr, key ssh.PublicKey) error {
         return nil
      },
}
client, err := ssh.Dial("tcp", config.Host+":22", sshConfig)
session, err := client.NewSession()
defer session.Close()
b, err := session.CombinedOutput(command)

When this session creation gives EOF error, is there any way to get back the ssh connection in working state?

If I consider redialing or reconnect when only if I get error on read/write then which design pattren will be useful here.

Thanks

Aucun commentaire:

Enregistrer un commentaire