From baf257adcb1fe224e6f04b1de744052ad7bc81fe Mon Sep 17 00:00:00 2001 From: Klaus Post Date: Fri, 24 Jun 2022 11:12:52 -0700 Subject: [PATCH] fix: health client leak when calling UpdateAllTargets (#15167) When `LoadBucketMetadataHandler` is called and `UpdateAllTargets` gets called. Since targets are rebuilt we cancel all. --- cmd/bucket-targets.go | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/cmd/bucket-targets.go b/cmd/bucket-targets.go index 01a0ea184..dc8c52e3e 100644 --- a/cmd/bucket-targets.go +++ b/cmd/bucket-targets.go @@ -24,7 +24,7 @@ import ( jsoniter "github.com/json-iterator/go" "github.com/minio/madmin-go" - minio "github.com/minio/minio-go/v7" + "github.com/minio/minio-go/v7" miniogo "github.com/minio/minio-go/v7" "github.com/minio/minio-go/v7/pkg/credentials" "github.com/minio/minio/internal/bucket/replication" @@ -272,17 +272,20 @@ func (sys *BucketTargetSys) UpdateAllTargets(bucket string, tgts *madmin.BucketT } sys.Lock() defer sys.Unlock() - if tgts == nil || tgts.Empty() { - // remove target and arn association - if tgts, ok := sys.targetsMap[bucket]; ok { - for _, t := range tgts { - if tgt, ok := sys.arnRemotesMap[t.Arn]; ok && tgt.healthCancelFn != nil { - tgt.healthCancelFn() - } - delete(sys.arnRemotesMap, t.Arn) + + // Remove existingtarget and arn association + if tgts, ok := sys.targetsMap[bucket]; ok { + for _, t := range tgts { + if tgt, ok := sys.arnRemotesMap[t.Arn]; ok && tgt.healthCancelFn != nil { + tgt.healthCancelFn() } + delete(sys.arnRemotesMap, t.Arn) } delete(sys.targetsMap, bucket) + } + + // No need for more if not adding anything + if tgts == nil || tgts.Empty() { sys.updateBandwidthLimit(bucket, 0) return }