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
Changes from 1 commit
ddfcffe
16540ed
8dee198
823ab91
b3675e1
c923ada
cb544ea
cd4c0fa
44f802d
7b5f2ab
8f6a20f
9ed72b9
7d2dbd3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
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") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Print the data? It might help with debugging if it ever happens. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added a print of the data. |
||
return nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is unnecessary. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed the |
||
} else if status.Code(err) != codes.Canceled { | ||
t.Errorf("expected status canceled error, instead received '%v'", err) | ||
} | ||
return nil | ||
}} | ||
|
@@ -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 | ||
}) | ||
} | ||
|
||
|
@@ -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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added an error check here. The error is an RPC status error |
||
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 | ||
|
@@ -4706,6 +4724,7 @@ func testClientSendDataAfterCloseSend(t *testing.T, e env) { | |
st.wantAnyFrame() | ||
st.wantAnyFrame() | ||
st.wantRSTStream(http2.ErrCodeStreamClosed) | ||
frameCheckingDone <- true | ||
<-sentMessage | ||
}) | ||
} | ||
|
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.
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.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.
Migrated to the
chan struct{}
pattern.