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
27 changes: 14 additions & 13 deletions test/end2end_test.go
Expand Up @@ -4647,21 +4647,21 @@ 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)
frameCheckingDone := make(chan struct{})
// To ensure goroutine for test does not end before RPC handler performs error checking.
handlerDone := make(chan bool, 1)
handlerDone := make(chan struct{})
te := newTest(t, e)
ts := &funcServer{streamingInputCall: func(stream testpb.TestService_StreamingInputCallServer) error {
defer func() {
handlerDone <- true
close(handlerDone)
}()
Copy link
Member

Choose a reason for hiding this comment

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

Just defer close(handlerDone) now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Made this change.

// Block on serverTester receiving RST_STREAM. This ensures server has closed stream before stream.Recv().
Copy link
Member

Choose a reason for hiding this comment

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

Please make sure to wrap comments at 80 columns for readability.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wrapped comments

<-frameCheckingDone
Copy link
Member

Choose a reason for hiding this comment

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

Comment here to explain why we need to block until the server has sent the RST_STREAM. And in the test below, too

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 comment.

_, err := stream.Recv()
data, err := stream.Recv()
if err == nil {
t.Error("unexpected data received in func server method")
return nil
t.Errorf("unexpected data received in func server method: '%v'", data)
} else if status.Code(err) != codes.Canceled {
t.Errorf("expected status canceled error, instead received '%v'", err)
t.Errorf("expected canceled error, instead received '%v'", err)
}
return nil
}}
Expand All @@ -4674,7 +4674,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
close(frameCheckingDone)
<-handlerDone
})
}
Expand All @@ -4690,14 +4690,15 @@ func (s) TestClientSendDataAfterCloseSend(t *testing.T) {

func testClientSendDataAfterCloseSend(t *testing.T, e env) {
// To ensure RST_STREAM is sent for illegal data write prior to execution of RPC handler.
frameCheckingDone := make(chan bool, 1)
frameCheckingDone := make(chan struct{})
// To ensure goroutine for test does not end before RPC handler performs error checking.
handlerDone := make(chan bool, 1)
handlerDone := make(chan struct{})
te := newTest(t, e)
ts := &funcServer{streamingInputCall: func(stream testpb.TestService_StreamingInputCallServer) error {
defer func() {
handlerDone <- true
close(handlerDone)
Copy link
Member

Choose a reason for hiding this comment

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

Same

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Made this change.

}()
// Block on serverTester receiving RST_STREAM. This ensures server has closed stream before stream.Recv().
<-frameCheckingDone
for {
_, err := stream.Recv()
Expand All @@ -4706,7 +4707,7 @@ func testClientSendDataAfterCloseSend(t *testing.T, e env) {
}
if err != nil {
if status.Code(err) != codes.Canceled {
t.Errorf("expected status canceled error, instead received '%v'", err)
t.Errorf("expected canceled error, instead received '%v'", err)
}
break
}
Expand All @@ -4728,7 +4729,7 @@ func testClientSendDataAfterCloseSend(t *testing.T, e env) {
st.wantAnyFrame()
st.wantAnyFrame()
st.wantRSTStream(http2.ErrCodeStreamClosed)
frameCheckingDone <- true
close(frameCheckingDone)
<-handlerDone
})
}
Expand Down