-
Notifications
You must be signed in to change notification settings - Fork 4.5k
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
Conversation
Also, do you mind adding tests for the behavior changes. And, is there a reason the PR is in draft? |
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. |
@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.) |
grpc-go/internal/transport/transport_test.go Line 1884 in f2fbb0e
|
@easwars, thanks for the pointer! I've added new test cases and this PR is no longer a draft. |
@easwars, will you have time to review this PR this week? |
internal/transport/http2_server.go
Outdated
@@ -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{ |
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.
Why is it required to assign the return value to a blank identifier instead of ignoring it? Here and other places in this PR.
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.
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.
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.
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.
t.Fatalf("Client failed to dial: %v", err) | ||
} | ||
defer mconn.Close() | ||
t.Run(test.name, func(t *testing.T) { |
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.
Did you change anything at all in this test's logic, or is it just indentation change because of adding a t.Run()
?
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.
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. |
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. |
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.
I think the changes look fine. Could you please handle the blank identifier assignment please.
internal/transport/http2_server.go
Outdated
@@ -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{ |
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.
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.
Adding @dfawley for second set of eyes and another ping on #5893 (comment). |
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.
Thank you for the fix! One comment about condition ordering, otherwise LGTM.
internal/transport/http2_server.go
Outdated
}) | ||
return nil | ||
} | ||
if !isGRPC { |
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.
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?
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.
Good point! Fixed.
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.
Thanks!
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 existingnet/http
server) already handled such requests this way. So now they behave consistently.Fixes #5892
RELEASE NOTES: