From b4f6901903b9f82714d50c0a6e55092658d30d2b Mon Sep 17 00:00:00 2001 From: Poorna Date: Wed, 13 Jul 2022 16:29:10 -0700 Subject: [PATCH] resync: Avoid concurrent access/write on map (#15286) fixes a crash ``` fatal error: concurrent map iteration and map write minio[19309]: goroutine 18640 [running]: minio[19309]: runtime.throw({0x27a3399?, 0x1785?}) minio[19309]: runtime/panic.go:992 +0x71 fp=0xc0062f1c80 sp=0xc0062f1c50 pc=0x438671 minio[19309]: runtime.mapiternext(0xc0062f1e90?) minio[19309]: runtime/map.go:871 +0x4eb fp=0xc0062f1cf0 sp=0xc0062f1c80 pc=0x41002b minio[19309]: github.com/minio/minio/cmd.(*ReplicationPool).periodicResyncMetaSave(0xc0056c00c0, {0x4d06a48, 0xc0005b2480}, {0x4d22fc0, 0xc0015ea0 ``` --- cmd/bucket-replication.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/cmd/bucket-replication.go b/cmd/bucket-replication.go index 00f86e977..f6ab3d6ef 100644 --- a/cmd/bucket-replication.go +++ b/cmd/bucket-replication.go @@ -2214,18 +2214,21 @@ func (p *ReplicationPool) loadResync(ctx context.Context, buckets []BucketInfo, for index := range buckets { meta, err := loadBucketResyncMetadata(ctx, buckets[index].Name, objAPI) if err != nil { - if errors.Is(err, errVolumeNotFound) { - meta = newBucketResyncStatus(buckets[index].Name) - } else { + if !errors.Is(err, errVolumeNotFound) { logger.LogIf(ctx, err) - continue } + continue } + p.resyncState.Lock() p.resyncState.statusMap[buckets[index].Name] = meta + p.resyncState.Unlock() } for index := range buckets { bucket := buckets[index].Name + p.resyncState.RLock() m, ok := p.resyncState.statusMap[bucket] + p.resyncState.RUnlock() + if ok { for arn, st := range m.TargetsMap { if st.ResyncStatus == ResyncFailed || st.ResyncStatus == ResyncStarted {