From d5b8e4d4ce4c13204ae33c5e2857b9b84d1dba4a Mon Sep 17 00:00:00 2001 From: Joshua Humphries <2035234+jhump@users.noreply.github.com> Date: Fri, 12 May 2023 12:50:32 -0400 Subject: [PATCH] fix nil-dereference panic (#395) --- invoke.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/invoke.go b/invoke.go index b5bae4b1..193c285f 100644 --- a/invoke.go +++ b/invoke.go @@ -264,8 +264,10 @@ func invokeServerStream(ctx context.Context, stub grpcdynamic.Stub, md *desc.Met // Now we can actually invoke the RPC! str, err := stub.InvokeRpcServerStream(ctx, md, req) - if respHeaders, err := str.Header(); err == nil { - handler.OnReceiveHeaders(respHeaders) + if str != nil { + if respHeaders, err := str.Header(); err == nil { + handler.OnReceiveHeaders(respHeaders) + } } // Download each response message @@ -288,7 +290,9 @@ func invokeServerStream(ctx context.Context, stub grpcdynamic.Stub, md *desc.Met return fmt.Errorf("grpc call for %q failed: %v", md.GetFullyQualifiedName(), err) } - handler.OnReceiveTrailers(stat, str.Trailer()) + if str != nil { + handler.OnReceiveTrailers(stat, str.Trailer()) + } return nil }