diff --git a/types/services/routine.go b/types/services/routine.go index 91a7a126..924470c3 100644 --- a/types/services/routine.go +++ b/types/services/routine.go @@ -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{}