From 21acd2993b4e60edc4e3a90fcb64851ff616f520 Mon Sep 17 00:00:00 2001 From: Sumit Anvekar <2293969+sumitanvekar@users.noreply.github.com> Date: Mon, 12 Jun 2023 23:30:30 +0530 Subject: [PATCH 1/2] fix: null pointer when connection not available --- internal/pkg/grpc/client.go | 5 +++++ internal/pkg/warmup/target.go | 1 + 2 files changed, 6 insertions(+) diff --git a/internal/pkg/grpc/client.go b/internal/pkg/grpc/client.go index 670a63b..032b1f8 100644 --- a/internal/pkg/grpc/client.go +++ b/internal/pkg/grpc/client.go @@ -122,6 +122,11 @@ func (c *Client) SendRequest(serviceMethod string, message string, headers []str interpolatedHeaders[i] = placeholders.InterpolatePlaceholders(header) } + if c.conn == nil { + log.Printf("No connection available. Skip making request.") + return response.Response{Duration: time.Duration(0), Err: err, Type: respType} + } + err = grpcurl.InvokeRPC(context.Background(), c.descriptorSource, c.conn, serviceMethod, interpolatedHeaders, loggingEventHandler, requestParser.Next) endTime := time.Now() if err != nil { diff --git a/internal/pkg/warmup/target.go b/internal/pkg/warmup/target.go index 9e8c138..4c80fcc 100644 --- a/internal/pkg/warmup/target.go +++ b/internal/pkg/warmup/target.go @@ -81,6 +81,7 @@ func (t Target) WaitForReadinessProbe(maxReadinessWaitDurationInSeconds int, hea connErr := t.readinessGrpcClient.Connect(nil) if connErr != nil { log.Printf("gRPC readiness client connect error: %v", connErr) + continue } err1 := t.readinessGrpcClient.SendRequest(request.ServiceMethod, "", headers, false) if err1.Err != nil { From 23ebdc4950a3bfc14f630d3637af3bc2245abed5 Mon Sep 17 00:00:00 2001 From: Sumit Anvekar <2293969+sumitanvekar@users.noreply.github.com> Date: Tue, 13 Jun 2023 06:27:25 +0530 Subject: [PATCH 2/2] fix: correct Err type --- internal/pkg/grpc/client.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/pkg/grpc/client.go b/internal/pkg/grpc/client.go index 032b1f8..db4f37f 100644 --- a/internal/pkg/grpc/client.go +++ b/internal/pkg/grpc/client.go @@ -16,6 +16,7 @@ package grpc import ( "bytes" + "errors" "fmt" "google.golang.org/grpc/credentials/insecure" "log" @@ -124,7 +125,7 @@ func (c *Client) SendRequest(serviceMethod string, message string, headers []str if c.conn == nil { log.Printf("No connection available. Skip making request.") - return response.Response{Duration: time.Duration(0), Err: err, Type: respType} + return response.Response{Duration: time.Duration(0), Err: errors.New("no connection available"), Type: respType} } err = grpcurl.InvokeRPC(context.Background(), c.descriptorSource, c.conn, serviceMethod, interpolatedHeaders, loggingEventHandler, requestParser.Next)