Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

ftp: wait for 60 seconds for connection Close then declare it dead

Nick Craig-Wood4846d9393d5d
diff --git a/backend/ftp/ftp.go b/backend/ftp/ftp.go
index fafe6b702..fafe7bc53 100644
--- a/backend/ftp/ftp.go
+++ b/backend/ftp/ftp.go
@@ -646,7 +646,21 @@ func (f *ftpReadCloser) Read(p []byte) (n int, err error) {
// Close the FTP reader and return the connection to the pool
func (f *ftpReadCloser) Close() error {
- err := f.rc.Close()
+ var err error
+ errchan := make(chan error, 1)
+ go func() {
+ errchan <- f.rc.Close()
+ }()
+ // Wait for Close for up to 60 seconds
+ timer := time.NewTimer(60 * time.Second)
+ select {
+ case err = <-errchan:
+ timer.Stop()
+ case <-timer.C:
+ // if timer fired assume no error but connection dead
+ fs.Errorf(f.f, "Timeout when waiting for connection Close")
+ return nil
+ }
// if errors while reading or closing, dump the connection
if err != nil || f.err != nil {
_ = f.c.Quit()