From f04520a6e3d0581815ceb6e7319c52fed5d26b24 Mon Sep 17 00:00:00 2001 From: Ankur Gupta <7876747+ankur0493@users.noreply.github.com> Date: Thu, 8 Jul 2021 13:22:28 +0530 Subject: [PATCH] operations: fix goroutine leak in case of copy retry Whenever transfer.Account() is called, a new goroutine acc.averageLoop() is started. This goroutine exits only when the channel acc.exit is closed. acc.exit is closed when acc.Done() is called, which happens during tr.Done(). However, if tr.Reset is called during a copy low level retry, it replaces the tr.acc, without calling acc.Done(), which results in the goroutine mentioned above never exiting. This commit calls acc.Done() during a tr.Reset() --- fs/accounting/transfer.go | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/accounting/transfer.go b/fs/accounting/transfer.go index 93de4bcbd..09d27cf17 100644 --- a/fs/accounting/transfer.go +++ b/fs/accounting/transfer.go @@ -132,6 +132,7 @@ func (tr *Transfer) Reset(ctx context.Context) { ci := fs.GetConfig(ctx) if acc != nil { + acc.Done() if err := acc.Close(); err != nil { fs.LogLevelPrintf(ci.StatsLogLevel, nil, "can't close account: %+v\n", err) }