micro / go-micro

A Go microservices framework
https://go-micro.dev
Apache License 2.0
21.86k stars 2.35k forks source link

[BUG]V4.10.2 rpc_client.go Call function easily happen RWMutex‘s read lock re-entry then deadlock #2708

Closed yuan0763 closed 2 months ago

yuan0763 commented 5 months ago

example:

type TestService struct { }

func (s *TestService) FuncA() error { //rpc call 127.0.0.1 node's funcB client.DefaultClient.Call( context.Background(), client.NewRequest("TestService", "TestService.FuncB", nil), nil, client.WithAddress("127.0.0.1:8080"), ) return nil }

func (s *TestService) FuncB() error { //get the rpcClient's write lock go func() { client.DefaultClient.Init() }() //rpc call 127.0.0.1 node's funcC, //rpcClient's mu read lock re-entry then deadlock client.DefaultClient.Call( context.Background(), client.NewRequest("TestService", "TestService.FuncC", nil), nil, client.WithAddress("127.0.0.1:8080"), ) return nil }

func (s *TestService) FuncC() error { return nil }

func TestRpcClient(t *testing.T) { s := &TestService{}

go func() {
    s.FuncA()
}()

time.Sleep(time.Minute)

}

wudi commented 3 months ago

do not use client.DefaultClient use client.NewClient instead