-
Notifications
You must be signed in to change notification settings - Fork 4.6k
client: Roll-forward PR #8278(with changes): Restore the existing behavior to return io.EOF on repeated RecvMsg() calls for client-streaming RPCs #8523
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6792a42
add extra state to track calls to client.recvmsg
Pranjali-2501 206ddf8
Revert "add extra state to track calls to client.recvmsg"
Pranjali-2501 42a184d
revert commit 20bd1e7
Pranjali-2501 6cb1c54
restore existing behaviour to return io.EOF on repeated client.RecvMs…
Pranjali-2501 6d1b015
removing TODO
Pranjali-2501 451d1cd
resolving nit
Pranjali-2501 6fc6a02
change variable name
Pranjali-2501 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -3590,9 +3590,6 @@ func testClientStreamingError(t *testing.T, e env) { | |||||
// Tests that a client receives a cardinality violation error for client-streaming | ||||||
// RPCs if the server doesn't send a message before returning status OK. | ||||||
func (s) TestClientStreamingCardinalityViolation_ServerHandlerMissingSendAndClose(t *testing.T) { | ||||||
// TODO : https://github.com/grpc/grpc-go/issues/8119 - remove `t.Skip()` | ||||||
// after this is fixed. | ||||||
t.Skip() | ||||||
ss := &stubserver.StubServer{ | ||||||
StreamingInputCallF: func(_ testgrpc.TestService_StreamingInputCallServer) error { | ||||||
// Returning status OK without sending a response message.This is a | ||||||
|
@@ -3741,6 +3738,165 @@ func (s) TestClientStreaming_ReturnErrorAfterSendAndClose(t *testing.T) { | |||||
} | ||||||
} | ||||||
|
||||||
// Tests that client receives a cardinality violation error for unary | ||||||
// RPCs if the server doesn't send a message before returning status OK. | ||||||
func (s) TestUnaryRPC_ServerSendsOnlyTrailersWithOK(t *testing.T) { | ||||||
lis, err := testutils.LocalTCPListener() | ||||||
if err != nil { | ||||||
t.Fatal(err) | ||||||
} | ||||||
defer lis.Close() | ||||||
|
||||||
ss := grpc.UnknownServiceHandler(func(any, grpc.ServerStream) error { | ||||||
return nil | ||||||
}) | ||||||
|
||||||
s := grpc.NewServer(ss) | ||||||
go s.Serve(lis) | ||||||
defer s.Stop() | ||||||
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) | ||||||
defer cancel() | ||||||
cc, err := grpc.NewClient(lis.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials())) | ||||||
if err != nil { | ||||||
t.Fatalf("grpc.NewClient(%q) failed unexpectedly: %v", lis.Addr(), err) | ||||||
} | ||||||
defer cc.Close() | ||||||
|
||||||
client := testgrpc.NewTestServiceClient(cc) | ||||||
if _, err = client.EmptyCall(ctx, &testpb.Empty{}); status.Code(err) != codes.Internal { | ||||||
t.Errorf("stream.RecvMsg() = %v, want error %v", status.Code(err), codes.Internal) | ||||||
} | ||||||
} | ||||||
|
||||||
// Tests the behavior for unary RPC when client calls RecvMsg() twice. | ||||||
// Second call to RecvMsg should fail with io.EOF. | ||||||
func (s) TestUnaryRPC_ClientCallRecvMsgTwice(t *testing.T) { | ||||||
e := tcpTLSEnv | ||||||
te := newTest(t, e) | ||||||
defer te.tearDown() | ||||||
|
||||||
te.startServer(&testServer{security: e.security}) | ||||||
|
||||||
cc := te.clientConn() | ||||||
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) | ||||||
defer cancel() | ||||||
|
||||||
desc := &grpc.StreamDesc{ | ||||||
StreamName: "UnaryCall", | ||||||
ServerStreams: false, | ||||||
ClientStreams: false, | ||||||
} | ||||||
stream, err := cc.NewStream(ctx, desc, "/grpc.testing.TestService/UnaryCall") | ||||||
if err != nil { | ||||||
t.Fatalf("cc.NewStream() failed unexpectedly: %v", err) | ||||||
} | ||||||
|
||||||
if err := stream.SendMsg(&testpb.SimpleRequest{}); err != nil { | ||||||
t.Fatalf("stream.SendMsg(_) = %v, want <nil>", err) | ||||||
} | ||||||
|
||||||
resp := &testpb.SimpleResponse{} | ||||||
if err := stream.RecvMsg(resp); err != nil { | ||||||
t.Fatalf("stream.RecvMsg() = %v , want <nil>", err) | ||||||
} | ||||||
|
||||||
if err = stream.RecvMsg(resp); err != io.EOF { | ||||||
t.Errorf("stream.RecvMsg() = %v, want error %v", err, io.EOF) | ||||||
} | ||||||
} | ||||||
|
||||||
// Tests the behavior for unary RPC when server calls SendMsg() twice. | ||||||
// Client should fail with cardinality violation error. | ||||||
func (s) TestUnaryRPC_ServerCallSendMsgTwice(t *testing.T) { | ||||||
lis, err := testutils.LocalTCPListener() | ||||||
if err != nil { | ||||||
t.Fatal(err) | ||||||
} | ||||||
defer lis.Close() | ||||||
|
||||||
s := grpc.NewServer() | ||||||
serviceDesc := grpc.ServiceDesc{ | ||||||
ServiceName: "grpc.testing.TestService", | ||||||
HandlerType: (*any)(nil), | ||||||
Methods: []grpc.MethodDesc{}, | ||||||
Streams: []grpc.StreamDesc{ | ||||||
{ | ||||||
StreamName: "UnaryCall", | ||||||
Handler: func(_ any, stream grpc.ServerStream) error { | ||||||
if err := stream.RecvMsg(&testpb.Empty{}); err != nil { | ||||||
t.Errorf("stream.RecvMsg() = %v, want <nil>", err) | ||||||
} | ||||||
|
||||||
if err = stream.SendMsg(&testpb.Empty{}); err != nil { | ||||||
t.Errorf("stream.SendMsg() = %v, want <nil>", err) | ||||||
} | ||||||
|
||||||
if err = stream.SendMsg(&testpb.Empty{}); err != nil { | ||||||
t.Errorf("stream.SendMsg() = %v, want <nil>", err) | ||||||
} | ||||||
return nil | ||||||
}, | ||||||
ClientStreams: false, | ||||||
ServerStreams: false, | ||||||
}, | ||||||
}, | ||||||
} | ||||||
s.RegisterService(&serviceDesc, &testServer{}) | ||||||
go s.Serve(lis) | ||||||
defer s.Stop() | ||||||
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) | ||||||
defer cancel() | ||||||
cc, err := grpc.NewClient(lis.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials())) | ||||||
if err != nil { | ||||||
t.Fatalf("grpc.NewClient(%q) failed unexpectedly: %v", lis.Addr(), err) | ||||||
} | ||||||
defer cc.Close() | ||||||
|
||||||
client := testgrpc.NewTestServiceClient(cc) | ||||||
if _, err = client.UnaryCall(ctx, &testpb.SimpleRequest{}); status.Code(err) != codes.Internal { | ||||||
t.Errorf("stream.RecvMsg() = %v, want error %v", status.Code(err), codes.Internal) | ||||||
} | ||||||
} | ||||||
|
||||||
// Tests the behavior for client-streaming RPC when client calls RecvMsg() twice. | ||||||
// Second call to RecvMsg should fail with io.EOF. | ||||||
func (s) TestClientStreaming_ClientCallRecvMsgTwice(t *testing.T) { | ||||||
ss := stubserver.StubServer{ | ||||||
StreamingInputCallF: func(stream testgrpc.TestService_StreamingInputCallServer) error { | ||||||
if err := stream.SendAndClose(&testpb.StreamingInputCallResponse{}); err != nil { | ||||||
t.Errorf("stream.SendAndClose(_) = %v, want <nil>", err) | ||||||
} | ||||||
return nil | ||||||
}, | ||||||
} | ||||||
if err := ss.Start(nil); err != nil { | ||||||
t.Fatal("Error starting server:", err) | ||||||
} | ||||||
defer ss.Stop() | ||||||
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) | ||||||
defer cancel() | ||||||
stream, err := ss.Client.StreamingInputCall(ctx) | ||||||
if err != nil { | ||||||
t.Fatalf(".StreamingInputCall(_) = _, %v, want <nil>", err) | ||||||
} | ||||||
if err := stream.Send(&testpb.StreamingInputCallRequest{}); err != nil { | ||||||
t.Fatalf("stream.Send(_) = %v, want <nil>", err) | ||||||
} | ||||||
if err := stream.CloseSend(); err != nil { | ||||||
t.Fatalf("stream.CloseSend() = %v, want <nil>", err) | ||||||
} | ||||||
resp := new(testpb.StreamingInputCallResponse) | ||||||
if err := stream.RecvMsg(resp); err != nil { | ||||||
t.Fatalf("stream.RecvMsg() = %v , want <nil>", err) | ||||||
} | ||||||
if err = stream.RecvMsg(resp); err != io.EOF { | ||||||
t.Errorf("stream.RecvMsg() = %v, want error %v", err, io.EOF) | ||||||
} | ||||||
} | ||||||
|
||||||
// Tests the behavior for server-side streaming when client calls SendMsg twice. | ||||||
// Second call to SendMsg should fail with Internal error and result in closing | ||||||
// the connection with a RST_STREAM. | ||||||
|
@@ -3981,7 +4137,7 @@ func (s) TestServerStreaming_ClientSendsZeroRequests(t *testing.T) { | |||||
} | ||||||
|
||||||
// Tests that a client receives a cardinality violation error for client-streaming | ||||||
// RPCs if the server call SendMsg multiple times. | ||||||
// RPCs if the server call SendMsg() multiple times. | ||||||
|
// RPCs if the server call SendMsg() multiple times. | |
// RPCs if the server calls SendMsg() multiple times. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Please expand
recv
toreceived
. The abbreviation is a bit ambiguous and could be interpreted as eitherreceive
orreceived
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.