Skip to content

Commit

Permalink
Fix the goroutine variable capturing in removeObjectsOneByOne
Browse files Browse the repository at this point in the history
This patch fixes classic golang for-loop variable capturing issue that
leeds to incorrect results in goroutines.

This is fixed in latest versions of golang, but this project uses go 1.15,
so it won't work as expected by an author.
  • Loading branch information
a-narsudinov committed Oct 27, 2023
1 parent 2540159 commit da3638e
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions pkg/s3/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,15 +197,15 @@ func (client *s3Client) removeObjectsOneByOne(bucketName, prefix string) error {

for object := range objectsCh {
guardCh <- 1
go func() {
err := client.minio.RemoveObject(client.ctx, bucketName, object.Key,
minio.RemoveObjectOptions{VersionID: object.VersionID})
go func(obj minio.ObjectInfo) {
err := client.minio.RemoveObject(client.ctx, bucketName, obj.Key,
minio.RemoveObjectOptions{VersionID: obj.VersionID})
if err != nil {
glog.Errorf("Failed to remove object %s, error: %s", object.Key, err)
glog.Errorf("Failed to remove object %s, error: %s", obj.Key, err)
removeErrors++
}
<- guardCh
}()
}(object)
}
for i := 0; i < parallelism; i++ {
guardCh <- 1
Expand Down

0 comments on commit da3638e

Please sign in to comment.