From e8eb658ba5b2cda4d525c39eb815f548fd0b8288 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Tue, 25 Feb 2020 11:38:13 +0000 Subject: [PATCH] ftp: fix lockup on failed upload when using concurrency limit #3984 Before this change if rclone failed to upload a file for some reason it would leak a concurrency token. When all the tokens were leaked then rclone would lock up. The fix returns the concurrency token regardless of the error state. --- backend/ftp/ftp.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/backend/ftp/ftp.go b/backend/ftp/ftp.go index 58bd8cab6..a818dd87b 100644 --- a/backend/ftp/ftp.go +++ b/backend/ftp/ftp.go @@ -207,7 +207,13 @@ func (f *Fs) putFtpConnection(pc **ftp.ServerConn, err error) { if f.opt.Concurrency > 0 { defer f.tokens.Put() } + if pc == nil { + return + } c := *pc + if c == nil { + return + } *pc = nil if err != nil { // If not a regular FTP error code then check the connection @@ -861,6 +867,7 @@ func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, op if err != nil { _ = c.Quit() // toss this connection to avoid sync errors remove() + o.fs.putFtpConnection(nil, err) return errors.Wrap(err, "update stor") } o.fs.putFtpConnection(&c, nil)