刚才的问题原因是测试程序中conn.close()未释放导致
This commit is contained in:
parent
fedf99cc78
commit
fa7dd9c925
|
|
@ -28,13 +28,14 @@ func main() {
|
|||
continue
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||
// conn, err := grpc.Dial("127.0.0.1:9001", grpc.WithBlock(), grpc.WithInsecure())
|
||||
conn, err := grpc.DialContext(ctx, fmt.Sprintf("%s:%d", node.Address, node.Port), grpc.WithBlock(), grpc.WithInsecure(), grpc.WithBalancerName("round_robin"))
|
||||
if err != nil {
|
||||
fmt.Printf("%v\n", err)
|
||||
cancel()
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
c := pb.NewHelloClient(conn)
|
||||
resp, err := c.Say(ctx, &pb.SayRequest{Name: "jiale", Day: "2008-08-08"})
|
||||
if err != nil {
|
||||
|
|
@ -45,6 +46,6 @@ func main() {
|
|||
log.WithFields(log.Fields{
|
||||
"func": "main",
|
||||
}).Infof("%s", resp.Reply)
|
||||
|
||||
conn.Close()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue