1
0
mirror of https://github.com/rclone/rclone.git synced 2025-03-11 05:38:17 +01:00

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

This helps with indefinite hangs when transferring very large files on
some ftp server.

Fixes 
This commit is contained in:
Nick Craig-Wood 2019-01-15 17:32:14 +00:00
parent fc4f20d52f
commit 4846d9393d

View File

@ -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 // Close the FTP reader and return the connection to the pool
func (f *ftpReadCloser) Close() error { 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 errors while reading or closing, dump the connection
if err != nil || f.err != nil { if err != nil || f.err != nil {
_ = f.c.Quit() _ = f.c.Quit()