fix(sftp): reconnect to server when connection was broken (#6416 close #6403)

* fix(sftp): reconnect to server when conn was broken (close #6403)

* fix(sftp): fix typo

---------

Co-authored-by: George Chen <gchen@isimarkets.com>
This commit is contained in:
George Chen
2024-05-09 14:53:25 +08:00
committed by GitHub
parent f261ef50cc
commit b57afd0a98
2 changed files with 41 additions and 1 deletions

View File

@ -4,6 +4,7 @@ import (
"path"
"github.com/pkg/sftp"
log "github.com/sirupsen/logrus"
"golang.org/x/crypto/ssh"
)
@ -30,6 +31,23 @@ func (d *SFTP) initClient() error {
return err
}
d.client, err = sftp.NewClient(conn)
if err == nil {
d.clientConnectionError = nil
go func(d *SFTP) {
d.clientConnectionError = d.client.Wait()
}(d)
}
return err
}
func (d *SFTP) clientReconnectOnConnectionError() error {
err := d.clientConnectionError
if err == nil {
return nil
}
log.Debugf("[sftp] discarding closed sftp connection: %v", err)
_ = d.client.Close()
err = d.initClient()
return err
}