Skip to content

Commit 65285b4

Browse files
phmxburaksezer
authored andcommitted
Fix data race in internal/cluster/routingtable/update.go
There is a data race between routing tables update go-routines when tests are ran with `-race` flag: ``` WARNING: DATA RACE Write at 0x00c00040ec20 by goroutine 298: github.com/olric-data/olric/internal/cluster/routingtable.(*RoutingTable).updateRoutingTableOnCluster.(*Members).Range.(*RoutingTable).updateRoutingTableOnCluster.func1.func2() /home/maxim/.local/go/pkg/mod/github.com/olric-data/[email protected]/internal/cluster/routingtable/update.go:88 +0xeb golang.org/x/sync/errgroup.(*Group).Go.func1() /home/maxim/.local/go/pkg/mod/golang.org/x/[email protected]/errgroup/errgroup.go:93 +0x86 Previous read at 0x00c00040ec20 by goroutine 297: github.com/olric-data/olric/internal/cluster/routingtable.(*RoutingTable).updateRoutingTableOnCluster.(*Members).Range.(*RoutingTable).updateRoutingTableOnCluster.func1.func2() /home/maxim/.local/go/pkg/mod/github.com/olric-data/[email protected]/internal/cluster/routingtable/update.go:88 +0x12f golang.org/x/sync/errgroup.(*Group).Go.func1() /home/maxim/.local/go/pkg/mod/golang.org/x/[email protected]/errgroup/errgroup.go:93 +0x86 ``` Same captured `err` variable is shared between several go-routines.
1 parent 23297a6 commit 65285b4

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

internal/cluster/routingtable/update.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func (r *RoutingTable) updateRoutingTableOnCluster() (map[discovery.Member]*left
8585
r.Members().Range(func(id uint64, tmp discovery.Member) bool {
8686
member := tmp
8787
g.Go(func() error {
88-
if err = sem.Acquire(r.ctx, 1); err != nil {
88+
if err := sem.Acquire(r.ctx, 1); err != nil {
8989
r.log.V(3).Printf("[ERROR] Failed to acquire semaphore to update routing table on %s: %v", member, err)
9090
return err
9191
}

0 commit comments

Comments
 (0)