mirror of https://github.com/statping/statping
Add timeout to grpc dial function call.
Signed-off-by: thatInfrastructureGuy <thatInfrastructureGuy@gmail.com>pull/806/head
parent
8f800e9b64
commit
24eeec99c9
|
@ -161,7 +161,13 @@ func CheckGrpc(s *Service, record bool) (*Service, error) {
|
|||
}
|
||||
}
|
||||
|
||||
conn, err := grpc.Dial(domain, grpcOption, grpc.WithBlock())
|
||||
// Context will cancel the request when timeout is exceeded.
|
||||
// Cancel the context when request is served within the timeout limit.
|
||||
timeout := time.Duration(s.Timeout) * time.Second
|
||||
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
||||
defer cancel()
|
||||
|
||||
conn, err := grpc.DialContext(ctx, domain, grpcOption, grpc.WithBlock())
|
||||
if err != nil {
|
||||
if record {
|
||||
RecordFailure(s, fmt.Sprintf("Dial Error %v", err), "connection")
|
||||
|
@ -169,12 +175,6 @@ func CheckGrpc(s *Service, record bool) (*Service, error) {
|
|||
return s, err
|
||||
}
|
||||
|
||||
// Context will cancel the request when timeout is exceeded.
|
||||
// Cancel the context when request is served within the timeout limit.
|
||||
timeout := time.Duration(s.Timeout) * time.Second
|
||||
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
||||
defer cancel()
|
||||
|
||||
// Create a new health check client
|
||||
c := healthpb.NewHealthClient(conn)
|
||||
in := &healthpb.HealthCheckRequest{}
|
||||
|
|
Loading…
Reference in New Issue