Skip to content
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

server: respond correctly to client headers with END_STREAM flag set #3803

Merged
merged 13 commits into from Aug 21, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 22 additions & 3 deletions test/end2end_test.go
Expand Up @@ -4646,13 +4646,19 @@ func (s) TestClientInitialHeaderEndStream(t *testing.T) {
}

func testClientInitialHeaderEndStream(t *testing.T, e env) {
// To ensure RST_STREAM is sent for illegal data write and not normal stream close.
frameCheckingDone := make(chan bool, 1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The typical way to implement this pattern is to make it a: chan struct{} (with no buffer) and close the channel when you want to indicate the thing happened.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Migrated to the chan struct{} pattern.

te := newTest(t, e)
ts := &funcServer{streamingInputCall: func(stream testpb.TestService_StreamingInputCallServer) error {
defer func() {
<-frameCheckingDone
}()
_, err := stream.Recv()
if err == nil {
errUnexpectedData := errors.New("unexpected data received in func server method")
t.Error(errUnexpectedData)
return errUnexpectedData
t.Error("unexpected data received in func server method")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Print the data? It might help with debugging if it ever happens.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a print of the data.

return nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unnecessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the return nil in the if block

} else if status.Code(err) != codes.Canceled {
t.Errorf("expected status canceled error, instead received '%v'", err)
}
return nil
}}
Expand All @@ -4665,6 +4671,7 @@ func testClientInitialHeaderEndStream(t *testing.T, e env) {
st.wantAnyFrame()
st.wantAnyFrame()
st.wantRSTStream(http2.ErrCodeStreamClosed)
dfawley marked this conversation as resolved.
Show resolved Hide resolved
frameCheckingDone <- true
})
}

Expand All @@ -4678,20 +4685,31 @@ func (s) TestClientSendDataAfterCloseSend(t *testing.T) {
}

func testClientSendDataAfterCloseSend(t *testing.T, e env) {
// To ensure RST_STREAM is sent for illegal data write and not normal stream close.
frameCheckingDone := make(chan bool, 1)
// To ensure goroutine for test does not end before RPC handler checks the SendMsg return value.
sentMessage := make(chan bool, 1)
te := newTest(t, e)
ts := &funcServer{streamingInputCall: func(stream testpb.TestService_StreamingInputCallServer) error {
defer func() {
<-frameCheckingDone
}()
for {
_, err := stream.Recv()
if err == io.EOF {
break
}
if err != nil {
if status.Code(err) != codes.Canceled {
t.Errorf("expected status canceled error, instead received '%v'", err)
}
break
}
}
if err := stream.SendMsg(nil); err == nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's test the actual error we expect to get from the stream here instead of "any error is fine".

I have a feeling it will be an RPC status error now, but maybe that's not right (#3575). We can just expect the wrong thing for now and leave a comment that it will need to be updated when #3575 is fixed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added an error check here. The error is an RPC status error Internal.

t.Error("expected error sending message on stream after stream closed on illegal data")
} else if status.Code(err) != codes.Internal {
t.Errorf("expected status internal error, instead received '%v'", err)
}
sentMessage <- true
return nil
Expand All @@ -4706,6 +4724,7 @@ func testClientSendDataAfterCloseSend(t *testing.T, e env) {
st.wantAnyFrame()
st.wantAnyFrame()
st.wantRSTStream(http2.ErrCodeStreamClosed)
frameCheckingDone <- true
<-sentMessage
})
}
Expand Down