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: fix a few issues where grpc server uses RST_STREAM for non-HTTP/2 errors #5893

Merged
merged 6 commits into from Jan 18, 2023

Conversation

jhump
Copy link
Member

@jhump jhump commented Dec 23, 2022

In addition to the 415 for an unsupported content-type, this also has the server respond with a 400 in the face of malformed application header values (invalid grpc-timeout, invalid base64-encoded binary header). The NewServerHandlerTransport function (for using the server with existing net/http server) already handled such requests this way. So now they behave consistently.

Fixes #5892

RELEASE NOTES:

  • server: fix a few issues where grpc server uses RST_STREAM for non-HTTP/2 errors

@jhump jhump marked this pull request as draft December 23, 2022 20:48
@easwars easwars self-assigned this Dec 27, 2022
@easwars easwars added this to the 1.53 Release milestone Dec 27, 2022
@easwars
Copy link
Contributor

easwars commented Dec 27, 2022

Also, do you mind adding tests for the behavior changes.

And, is there a reason the PR is in draft?

@github-actions
Copy link

github-actions bot commented Jan 2, 2023

This PR is labeled as requiring an update from the reporter, and no update has been received after 6 days. If no update is provided in the next 7 days, this issue will be automatically closed.

@github-actions github-actions bot added the stale label Jan 2, 2023
@jhump
Copy link
Member Author

jhump commented Jan 3, 2023

And, is there a reason the PR is in draft?

@easwars, I was getting tests green and trying to figure out how to write new tests for this. It looks like there isn't much of a test fixture for this part of the code, so new tests will have a bit of setup boiler-plate. (If I'm wrong, please point me at an existing test that does similar setup as I'll need.)

@easwars
Copy link
Contributor

easwars commented Jan 3, 2023

func (s) TestHeadersHTTPStatusGRPCStatus(t *testing.T) {
is one of the tests which verifies the returned status code. Maybe you can add to that?

@jhump jhump marked this pull request as ready for review January 3, 2023 23:06
@jhump
Copy link
Member Author

jhump commented Jan 3, 2023

@easwars, thanks for the pointer! I've added new test cases and this PR is no longer a draft.

@jhump
Copy link
Member Author

jhump commented Jan 11, 2023

@easwars, will you have time to review this PR this week?

internal/transport/handler_server_test.go Outdated Show resolved Hide resolved
internal/transport/http2_server.go Outdated Show resolved Hide resolved
@@ -445,8 +447,8 @@ func (t *http2Server) operateHeaders(frame *http2.MetaHeadersFrame, handle func(
if logger.V(logLevel) {
logger.Errorf("transport: %v", errMsg)
}
t.controlBuf.put(&earlyAbortStream{
httpStatus: 400,
_ = t.controlBuf.put(&earlyAbortStream{
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is it required to assign the return value to a blank identifier instead of ignoring it? Here and other places in this PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

My IDE warns about code that ignores errors, which is what this function returns. This is a common analysis in CI (via tools like errcheck), to prevent mistakes where code forgets to check errors. So I added the _ = to make it explicit that I am ignoring the returned error (which suppresses the yellow indicator in GoLand).

I am happy to undo this if you want.

Copy link
Contributor

Choose a reason for hiding this comment

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

We generally don't prefer the _ = option. If and where it makes sense, we prefer adding a small comment saying why it is safe to ignore the error. So, if you could do that, that would be great.

internal/transport/http2_server.go Show resolved Hide resolved
internal/transport/http2_server.go Outdated Show resolved Hide resolved
t.Fatalf("Client failed to dial: %v", err)
}
defer mconn.Close()
t.Run(test.name, func(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you change anything at all in this test's logic, or is it just indentation change because of adding a t.Run()?

Copy link
Member Author

Choose a reason for hiding this comment

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

Just indenting. You can confirm by hiding whitespace changes in the diff:
image
The only other change was augmenting the error message on line 2061.

@easwars
Copy link
Contributor

easwars commented Jan 11, 2023

@easwars, will you have time to review this PR this week?

Apologies for the delay. Holidays and sickness to blame.

@jhump
Copy link
Member Author

jhump commented Jan 11, 2023

Apologies for the delay. Holidays and sickness to blame.

@easwars, no problem! I hope you're feeling better. And Happy New Year!

I think I've answered your questions and pushed a change to address one of them.

@jhump jhump removed their assignment Jan 11, 2023
@github-actions
Copy link

This PR is labeled as requiring an update from the reporter, and no update has been received after 6 days. If no update is provided in the next 7 days, this issue will be automatically closed.

Copy link
Contributor

@easwars easwars left a comment

Choose a reason for hiding this comment

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

I think the changes look fine. Could you please handle the blank identifier assignment please.

@@ -445,8 +447,8 @@ func (t *http2Server) operateHeaders(frame *http2.MetaHeadersFrame, handle func(
if logger.V(logLevel) {
logger.Errorf("transport: %v", errMsg)
}
t.controlBuf.put(&earlyAbortStream{
httpStatus: 400,
_ = t.controlBuf.put(&earlyAbortStream{
Copy link
Contributor

Choose a reason for hiding this comment

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

We generally don't prefer the _ = option. If and where it makes sense, we prefer adding a small comment saying why it is safe to ignore the error. So, if you could do that, that would be great.

internal/transport/http2_server.go Outdated Show resolved Hide resolved
@easwars
Copy link
Contributor

easwars commented Jan 18, 2023

Adding @dfawley for second set of eyes and another ping on #5893 (comment).

Copy link
Member

@dfawley dfawley left a comment

Choose a reason for hiding this comment

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

Thank you for the fix! One comment about condition ordering, otherwise LGTM.

})
return nil
}
if !isGRPC {
Copy link
Member

Choose a reason for hiding this comment

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

It seems to me like this should come first -- why complain about the syntax of some grpc headers if the other side isn't even speaking grpc?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point! Fixed.

@jhump jhump removed their assignment Jan 18, 2023
Copy link
Member

@dfawley dfawley left a comment

Choose a reason for hiding this comment

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

Thanks!

@dfawley dfawley changed the title fix a few issues where grpc server resets stream even for non-protocol errors server: fix a few issues where grpc server uses RST_STREAM for non-HTTP/2 errors Jan 18, 2023
@dfawley dfawley merged commit 9b9b381 into grpc:master Jan 18, 2023
1 check passed
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

grpc server resets HTTP/2 stream with "PROTOCOL_ERROR" on wrong content-type
5 participants