Skip to content

Commit

Permalink
invoking client-streaming RPC can panic (#262)
Browse files Browse the repository at this point in the history
  • Loading branch information
jhump authored Oct 7, 2021
1 parent b9d2d8c commit 76bbede
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions invoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,15 +227,19 @@ func invokeClientStream(ctx context.Context, stub grpcdynamic.Stub, md *desc.Met
return fmt.Errorf("grpc call for %q failed: %v", md.GetFullyQualifiedName(), err)
}

if respHeaders, err := str.Header(); err == nil {
handler.OnReceiveHeaders(respHeaders)
if str != nil {
if respHeaders, err := str.Header(); err == nil {
handler.OnReceiveHeaders(respHeaders)
}
}

if stat.Code() == codes.OK {
handler.OnReceiveResponse(resp)
}

handler.OnReceiveTrailers(stat, str.Trailer())
if str != nil {
handler.OnReceiveTrailers(stat, str.Trailer())
}

return nil
}
Expand Down Expand Up @@ -334,8 +338,10 @@ func invokeBidi(ctx context.Context, stub grpcdynamic.Stub, md *desc.MethodDescr
}()
}

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
Expand All @@ -362,7 +368,9 @@ func invokeBidi(ctx context.Context, stub grpcdynamic.Stub, md *desc.MethodDescr
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
}
Expand Down

0 comments on commit 76bbede

Please sign in to comment.