Skip to content

Commit 21acf06

Browse files
fix(jobs): race on objectCount in deleteStorageObjects
The storage-object reaper incremented objectCount in the producer goroutine and read it in the post-drain slog with no happens-before guarantee. CI's -race build (which the new coverage tests now exercise end-to-end) flagged it. Promote to atomic.Int64. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 7e521b0 commit 21acf06

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

internal/jobs/expire.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"log/slog"
88
"strings"
9+
"sync/atomic"
910
"time"
1011

1112
madmin "github.com/minio/madmin-go/v3"
@@ -570,7 +571,11 @@ func deleteStorageObjects(ctx context.Context, deleter S3BackupDeleter, bucket,
570571
// with thousands of objects doesn't pull the whole listing into memory —
571572
// the same pipe pattern as team_deletion_executor.deleteS3BackupsForToken.
572573
objectsCh := make(chan minio.ObjectInfo, 32)
573-
var objectCount int
574+
// objectCount is incremented in the producer goroutine below and read
575+
// after the RemoveObjects drain loop on the consumer side — use an
576+
// atomic so the cross-goroutine read in the final slog is race-free
577+
// (the -race build flagged the plain-int read otherwise).
578+
var objectCount atomic.Int64
574579
go func() {
575580
defer close(objectsCh)
576581
defer func() {
@@ -591,7 +596,7 @@ func deleteStorageObjects(ctx context.Context, deleter S3BackupDeleter, bucket,
591596
)
592597
return
593598
}
594-
objectCount++
599+
objectCount.Add(1)
595600
select {
596601
case objectsCh <- obj:
597602
case <-ctx.Done():
@@ -617,7 +622,7 @@ func deleteStorageObjects(ctx context.Context, deleter S3BackupDeleter, bucket,
617622
"resource_id", resourceID,
618623
"token", logsafe.Token(token),
619624
"prefix", prefix,
620-
"objects_listed", objectCount,
625+
"objects_listed", objectCount.Load(),
621626
"remove_errors", removeErrors,
622627
"job_id", jobID,
623628
)

0 commit comments

Comments
 (0)