Skip to content

Commit b6e98ae

Browse files
fix: found races in accessing globalLocalDrives (minio#19069)
make a copy before accessing globalLocalDrives Bonus: update console v0.46.0 Signed-off-by: Harshavardhana <[email protected]>
1 parent 00dcba9 commit b6e98ae

17 files changed

+55
-26
lines changed

.github/workflows/multipart/migrate.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ if [ ! -f ./mc ]; then
2525
fi
2626

2727
(
28-
cd /tmp
29-
go install github.com/minio/minio/docs/debugging/s3-check-md5@master
28+
cd ./docs/debugging/s3-check-md5
29+
go install -v
3030
)
3131

3232
export RELEASE=RELEASE.2023-08-29T23-07-35Z

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,9 @@ docker: build ## builds minio docker container
177177
@docker build -q --no-cache -t $(TAG) . -f Dockerfile
178178

179179
install-race: checks ## builds minio to $(PWD)
180-
@echo "Building minio binary to './minio'"
180+
@echo "Building minio binary with -race to './minio'"
181181
@GORACE=history_size=7 CGO_ENABLED=1 go build -tags kqueue -race -trimpath --ldflags "$(LDFLAGS)" -o $(PWD)/minio 1>/dev/null
182-
@echo "Installing minio binary to '$(GOPATH)/bin/minio'"
182+
@echo "Installing minio binary with -race to '$(GOPATH)/bin/minio'"
183183
@mkdir -p $(GOPATH)/bin && cp -f $(PWD)/minio $(GOPATH)/bin/minio
184184

185185
install: build ## builds minio and installs it to $GOPATH/bin.

buildscripts/rewrite-old-new.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,11 @@ function verify_rewrite() {
8787
exit 1
8888
fi
8989

90-
go install github.com/minio/minio/docs/debugging/s3-check-md5@master
90+
(
91+
cd ./docs/debugging/s3-check-md5
92+
go install -v
93+
)
94+
9195
if ! s3-check-md5 \
9296
-debug \
9397
-versions \

cmd/background-newdisks-heal-ops.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ func initAutoHeal(ctx context.Context, objAPI ObjectLayer) {
353353

354354
func getLocalDisksToHeal() (disksToHeal Endpoints) {
355355
globalLocalDrivesMu.RLock()
356-
localDrives := globalLocalDrives
356+
localDrives := cloneDrives(globalLocalDrives)
357357
globalLocalDrivesMu.RUnlock()
358358
for _, disk := range localDrives {
359359
_, err := disk.GetDiskID()

cmd/bucket-replication.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3393,7 +3393,7 @@ func (p *ReplicationPool) persistToDrive(ctx context.Context, v MRFReplicateEntr
33933393
}
33943394

33953395
globalLocalDrivesMu.RLock()
3396-
localDrives := globalLocalDrives
3396+
localDrives := cloneDrives(globalLocalDrives)
33973397
globalLocalDrivesMu.RUnlock()
33983398

33993399
for _, localDrive := range localDrives {
@@ -3460,7 +3460,7 @@ func (p *ReplicationPool) loadMRF() (mrfRec MRFReplicateEntries, err error) {
34603460
}
34613461

34623462
globalLocalDrivesMu.RLock()
3463-
localDrives := globalLocalDrives
3463+
localDrives := cloneDrives(globalLocalDrives)
34643464
globalLocalDrivesMu.RUnlock()
34653465

34663466
for _, localDrive := range localDrives {

cmd/metrics-resource.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ func collectDriveMetrics(m madmin.RealtimeMetrics) {
274274
}
275275

276276
globalLocalDrivesMu.RLock()
277-
localDrives := globalLocalDrives
277+
localDrives := cloneDrives(globalLocalDrives)
278278
globalLocalDrivesMu.RUnlock()
279279

280280
for _, d := range localDrives {

cmd/peer-rest-server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,7 @@ var errUnsupportedSignal = fmt.Errorf("unsupported signal")
786786

787787
func waitingDrivesNode() map[string]madmin.DiskMetrics {
788788
globalLocalDrivesMu.RLock()
789-
localDrives := globalLocalDrives
789+
localDrives := cloneDrives(globalLocalDrives)
790790
globalLocalDrivesMu.RUnlock()
791791

792792
errs := make([]error, len(localDrives))

cmd/peer-s3-server.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func (s *peerS3Server) HealthHandler(w http.ResponseWriter, r *http.Request) {
8282

8383
func healBucketLocal(ctx context.Context, bucket string, opts madmin.HealOpts) (res madmin.HealResultItem, err error) {
8484
globalLocalDrivesMu.RLock()
85-
localDrives := globalLocalDrives
85+
localDrives := cloneDrives(globalLocalDrives)
8686
globalLocalDrivesMu.RUnlock()
8787

8888
// Initialize sync waitgroup.
@@ -206,7 +206,7 @@ func healBucketLocal(ctx context.Context, bucket string, opts madmin.HealOpts) (
206206

207207
func listBucketsLocal(ctx context.Context, opts BucketOptions) (buckets []BucketInfo, err error) {
208208
globalLocalDrivesMu.RLock()
209-
localDrives := globalLocalDrives
209+
localDrives := cloneDrives(globalLocalDrives)
210210
globalLocalDrivesMu.RUnlock()
211211

212212
quorum := (len(localDrives) / 2)
@@ -252,9 +252,15 @@ func listBucketsLocal(ctx context.Context, opts BucketOptions) (buckets []Bucket
252252
return buckets, nil
253253
}
254254

255+
func cloneDrives(drives []StorageAPI) []StorageAPI {
256+
newDrives := make([]StorageAPI, len(drives))
257+
copy(newDrives, drives)
258+
return newDrives
259+
}
260+
255261
func getBucketInfoLocal(ctx context.Context, bucket string, opts BucketOptions) (BucketInfo, error) {
256262
globalLocalDrivesMu.RLock()
257-
localDrives := globalLocalDrives
263+
localDrives := cloneDrives(globalLocalDrives)
258264
globalLocalDrivesMu.RUnlock()
259265

260266
g := errgroup.WithNErrs(len(localDrives)).WithConcurrency(32)
@@ -303,7 +309,7 @@ func getBucketInfoLocal(ctx context.Context, bucket string, opts BucketOptions)
303309

304310
func deleteBucketLocal(ctx context.Context, bucket string, opts DeleteBucketOptions) error {
305311
globalLocalDrivesMu.RLock()
306-
localDrives := globalLocalDrives
312+
localDrives := cloneDrives(globalLocalDrives)
307313
globalLocalDrivesMu.RUnlock()
308314

309315
g := errgroup.WithNErrs(len(localDrives)).WithConcurrency(32)
@@ -341,7 +347,7 @@ func deleteBucketLocal(ctx context.Context, bucket string, opts DeleteBucketOpti
341347

342348
func makeBucketLocal(ctx context.Context, bucket string, opts MakeBucketOptions) error {
343349
globalLocalDrivesMu.RLock()
344-
localDrives := globalLocalDrives
350+
localDrives := cloneDrives(globalLocalDrives)
345351
globalLocalDrivesMu.RUnlock()
346352

347353
g := errgroup.WithNErrs(len(localDrives)).WithConcurrency(32)

docs/bucket/replication/delete-replication.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,13 @@ echo "=== myminio1"
7575
echo "=== myminio2"
7676
./mc ls --versions myminio2/testbucket/dir/file
7777

78-
versionId="$(mc ls --json --versions myminio1/testbucket/dir/ | tail -n1 | jq -r .versionId)"
78+
versionId="$(./mc ls --json --versions myminio1/testbucket/dir/ | tail -n1 | jq -r .versionId)"
7979

80-
aws s3api --endpoint-url http://localhost:9001 --profile minio delete-object --bucket testbucket --key dir/file --version-id "$versionId"
80+
aws configure set aws_access_key_id minioadmin --profile minioadmin
81+
aws configure set aws_secret_access_key minioadmin --profile minioadmin
82+
aws configure set default.region us-east-1 --profile minioadmin
83+
84+
aws s3api --endpoint-url http://localhost:9001 --profile minioadmin delete-object --bucket testbucket --key dir/file --version-id "$versionId"
8185

8286
./mc ls -r --versions myminio1/testbucket >/tmp/myminio1.txt
8387
./mc ls -r --versions myminio2/testbucket >/tmp/myminio2.txt

docs/bucket/replication/setup_3site_replication.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ unset MINIO_KMS_KES_KEY_FILE
4141
unset MINIO_KMS_KES_ENDPOINT
4242
unset MINIO_KMS_KES_KEY_NAME
4343

44-
go install github.com/minio/minio/docs/debugging/s3-check-md5@latest
44+
(
45+
cd ./docs/debugging/s3-check-md5
46+
go install -v
47+
)
4548

4649
wget -O mc https://dl.minio.io/client/mc/release/linux-amd64/mc &&
4750
chmod +x mc

0 commit comments

Comments
 (0)