Skip to content

Commit c10b0a5

Browse files
happyalujohanbrandhorst
authored andcommitted
Disable IOReaderFactory for streaming requests (grpc-ecosystem#896)
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. Fixes grpc-ecosystem#894
1 parent ee8c991 commit c10b0a5

File tree

4 files changed

+11
-38
lines changed

4 files changed

+11
-38
lines changed

examples/proto/examplepb/flow_combination.pb.gw.go

Lines changed: 2 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/proto/examplepb/stream.pb.gw.go

Lines changed: 2 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

protoc-gen-grpc-gateway/gengateway/template.go

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -236,11 +236,7 @@ func request_{{.Method.Service.GetName}}_{{.Method.GetName}}_{{.Index}}(ctx cont
236236
grpclog.Infof("Failed to start streaming: %v", err)
237237
return nil, metadata, err
238238
}
239-
newReader, berr := utilities.IOReaderFactory(req.Body)
240-
if berr != nil {
241-
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr)
242-
}
243-
dec := marshaler.NewDecoder(newReader())
239+
dec := marshaler.NewDecoder(req.Body)
244240
for {
245241
var protoReq {{.Method.RequestType.GoType .Method.Service.File.GoPkg.Path}}
246242
err = dec.Decode(&protoReq)
@@ -303,8 +299,8 @@ var (
303299
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
304300
} else {
305301
protoReq.{{.FieldMaskField}} = fieldMask
306-
}
307-
} {{end}}
302+
}
303+
} {{end}}
308304
{{end}}
309305
{{end}}
310306
{{if .PathParams}}
@@ -378,11 +374,7 @@ var (
378374
grpclog.Infof("Failed to start streaming: %v", err)
379375
return nil, metadata, err
380376
}
381-
newReader, berr := utilities.IOReaderFactory(req.Body)
382-
if berr != nil {
383-
return nil, metadata, berr
384-
}
385-
dec := marshaler.NewDecoder(newReader())
377+
dec := marshaler.NewDecoder(req.Body)
386378
handleSend := func() error {
387379
var protoReq {{.Method.RequestType.GoType .Method.Service.File.GoPkg.Path}}
388380
err := dec.Decode(&protoReq)

protoc-gen-grpc-gateway/gengateway/template_test.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -391,9 +391,6 @@ func TestApplyTemplateRequestWithClientStreaming(t *testing.T) {
391391
if want := spec.sigWant; !strings.Contains(got, want) {
392392
t.Errorf("applyTemplate(%#v) = %s; want to contain %s", file, got, want)
393393
}
394-
if want := `marshaler.NewDecoder(newReader()`; !strings.Contains(got, want) {
395-
t.Errorf("applyTemplate(%#v) = %s; want to contain %s", file, got, want)
396-
}
397394
if want := `func RegisterExampleServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {`; !strings.Contains(got, want) {
398395
t.Errorf("applyTemplate(%#v) = %s; want to contain %s", file, got, want)
399396
}
@@ -482,7 +479,7 @@ func TestAllowPatchFeature(t *testing.T) {
482479
}
483480
}
484481

485-
func TestIdentifierCapitalization(t *testing.T){
482+
func TestIdentifierCapitalization(t *testing.T) {
486483
msgdesc1 := &protodescriptor.DescriptorProto{
487484
Name: proto.String("Exam_pleRequest"),
488485
}
@@ -492,12 +489,12 @@ func TestIdentifierCapitalization(t *testing.T){
492489
meth1 := &protodescriptor.MethodDescriptorProto{
493490
Name: proto.String("ExampleGe2t"),
494491
InputType: proto.String("Exam_pleRequest"),
495-
OutputType: proto.String("example_response"),
492+
OutputType: proto.String("example_response"),
496493
}
497494
meth2 := &protodescriptor.MethodDescriptorProto{
498495
Name: proto.String("Exampl_eGet"),
499496
InputType: proto.String("Exam_pleRequest"),
500-
OutputType: proto.String("example_response"),
497+
OutputType: proto.String("example_response"),
501498
}
502499
svc := &protodescriptor.ServiceDescriptorProto{
503500
Name: proto.String("Example"),

0 commit comments

Comments
 (0)