Skip to content

Commit

Permalink
bugfix: disable IOReaderFactory for streaming requests
Browse files Browse the repository at this point in the history
An IOReaderFactory was being used to wrap request body for client/bidi streaming
requests.  This was causing the requests to be fully buffered before being sent
to the grpc server, thereby breaking streaming.  This commit changes that to
directly use request body.
  • Loading branch information
happyalu committed Mar 6, 2019
1 parent 87b57f5 commit 46fefbe
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 37 deletions.
12 changes: 2 additions & 10 deletions examples/proto/examplepb/flow_combination.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 2 additions & 10 deletions examples/proto/examplepb/stream.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 4 additions & 12 deletions protoc-gen-grpc-gateway/gengateway/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,7 @@ func request_{{.Method.Service.GetName}}_{{.Method.GetName}}_{{.Index}}(ctx cont
grpclog.Infof("Failed to start streaming: %v", err)
return nil, metadata, err
}
newReader, berr := utilities.IOReaderFactory(req.Body)
if berr != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr)
}
dec := marshaler.NewDecoder(newReader())
dec := marshaler.NewDecoder(req.Body)
for {
var protoReq {{.Method.RequestType.GoType .Method.Service.File.GoPkg.Path}}
err = dec.Decode(&protoReq)
Expand Down Expand Up @@ -303,8 +299,8 @@ var (
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
} else {
protoReq.{{.FieldMaskField}} = fieldMask
}
} {{end}}
}
} {{end}}
{{end}}
{{end}}
{{if .PathParams}}
Expand Down Expand Up @@ -378,11 +374,7 @@ var (
grpclog.Infof("Failed to start streaming: %v", err)
return nil, metadata, err
}
newReader, berr := utilities.IOReaderFactory(req.Body)
if berr != nil {
return nil, metadata, berr
}
dec := marshaler.NewDecoder(newReader())
dec := marshaler.NewDecoder(req.Body)
handleSend := func() error {
var protoReq {{.Method.RequestType.GoType .Method.Service.File.GoPkg.Path}}
err := dec.Decode(&protoReq)
Expand Down
10 changes: 5 additions & 5 deletions protoc-gen-grpc-gateway/gengateway/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,8 @@ func TestApplyTemplateRequestWithClientStreaming(t *testing.T) {
if want := spec.sigWant; !strings.Contains(got, want) {
t.Errorf("applyTemplate(%#v) = %s; want to contain %s", file, got, want)
}
if want := `marshaler.NewDecoder(newReader()`; !strings.Contains(got, want) {
t.Errorf("applyTemplate(%#v) = %s; want to contain %s", file, got, want)
if want := `marshaler.NewDecoder(newReader()`; strings.Contains(got, want) {
t.Errorf("applyTemplate(%#v) = %s; should not contain %s", file, got, want)
}
if want := `func RegisterExampleServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {`; !strings.Contains(got, want) {
t.Errorf("applyTemplate(%#v) = %s; want to contain %s", file, got, want)
Expand Down Expand Up @@ -482,7 +482,7 @@ func TestAllowPatchFeature(t *testing.T) {
}
}

func TestIdentifierCapitalization(t *testing.T){
func TestIdentifierCapitalization(t *testing.T) {
msgdesc1 := &protodescriptor.DescriptorProto{
Name: proto.String("Exam_pleRequest"),
}
Expand All @@ -492,12 +492,12 @@ func TestIdentifierCapitalization(t *testing.T){
meth1 := &protodescriptor.MethodDescriptorProto{
Name: proto.String("ExampleGe2t"),
InputType: proto.String("Exam_pleRequest"),
OutputType: proto.String("example_response"),
OutputType: proto.String("example_response"),
}
meth2 := &protodescriptor.MethodDescriptorProto{
Name: proto.String("Exampl_eGet"),
InputType: proto.String("Exam_pleRequest"),
OutputType: proto.String("example_response"),
OutputType: proto.String("example_response"),
}
svc := &protodescriptor.ServiceDescriptorProto{
Name: proto.String("Example"),
Expand Down

0 comments on commit 46fefbe

Please sign in to comment.