- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 555
 
Open
Description
There is a race condition when getting the process ID right away after the cluster starts. It seems .onClusterTopology() conflicts with cluster.Get().
To Reproduce
- Create a localhost cluster (only one node) with default Consul
 - Get process ID (i.e. c.Get("abc", "hello"))
 - run code with race detection
 
Test code:
import (
	"fmt"
	"github.com/asynkron/protoactor-go/actor"
	"github.com/asynkron/protoactor-go/cluster"
	"github.com/asynkron/protoactor-go/cluster/clusterproviders/consul"
	"github.com/asynkron/protoactor-go/cluster/identitylookup/disthash"
	"github.com/asynkron/protoactor-go/remote"
)
type HelloRequest struct {
	Name string
}
func main() {
	c := startNode()
	fmt.Print("\nBoot other nodes and press Enter\n")
	pid := c.Get("abc", "hello")
	fmt.Printf("Got pid %v", pid)
	res, _ := c.Request("abc", "hello", HelloRequest{Name: "Roger"})
	fmt.Printf("Got response %v", res)
	fmt.Println()
	c.Shutdown(true)
}
func startNode() *cluster.Cluster {
	system := actor.NewActorSystem()
	provider, _ := consul.New()
	lookup := disthash.New()
	config := remote.Configure("localhost", 0)
	clusterConfig := cluster.Configure("my-cluster", provider, lookup, config)
	c := cluster.New(system, clusterConfig)
	c.StartMember()
	return c
}
Cmd to run:
go run -race main.go 
Output:
WARNING: DATA RACE
Read at 0x00c000710098 by main goroutine:
  github.com/asynkron/protoactor-go/cluster/identitylookup/disthash.(*Manager).Get()
      /..../go/pkg/mod/github.com/asynkron/[email protected]/cluster/identitylookup/disthash/manager.go:75 +0x44
  github.com/asynkron/protoactor-go/cluster/identitylookup/disthash.(*IdentityLookup).Get()
  
  Previous write at 0x00c000710098 by goroutine 39:
  github.com/asynkron/protoactor-go/cluster/identitylookup/disthash.(*Manager).onClusterTopology()
      /..../go/pkg/mod/github.com/asynkron/[email protected]/cluster/identitylookup/disthash/manager.go:69 +0x464
  github.com/asynkron/protoactor-go/cluster/identitylookup/disthash.(*Manager).Start.func2()
Env:
MacOS Monterey v12.7.6
MacBook Pro mid 2015
Go v1.23.0
Expected behavior
Process ID creation or retrieval should not lead to race conditions to avoid data inconsistency.
cupen, TheBeachMaster and calvin2021y
Metadata
Metadata
Assignees
Labels
No labels