Closed yuan0763 closed 2 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)
}
do not use client.DefaultClient use client.NewClient instead
client.DefaultClient
client.NewClient
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{}
}