-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
http3: handle ErrAbortHandler when the handler panics #3575
Conversation
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
http3/server.go
Outdated
@@ -575,7 +581,7 @@ func (s *Server) handleRequest(conn quic.Connection, str quic.Stream, decoder *q | |||
var panicked bool | |||
func() { | |||
defer func() { | |||
if p := recover(); p != nil { | |||
if p := recover(); p != nil && err != ErrAbortHandler { |
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 not just reuse the http.ErrAbortHandler
?
I think we have to be a little bit more careful here, the if
here also sets panicked
to true
. We only want to prevent the logging, right?
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 didn't know about http.ErrAbortHandler
, let me look into that a bit more.
Isn't panicked
only set if p
is not nil
and not ErrAbortHandler
/http.ErrAbortHandler
?
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.
/me is an idiot and realizes he should have just used the variable from the stdlib instead of redefining it. Thanks, I'll do that.
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.
Isn't panicked only set if p is not nil and not ErrAbortHandler/http.ErrAbortHandler?
What's the expectation when ErrAbortHandler
is raised? I thought that the status code should be 500 then, not 200 (that's what panicked
controls).
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.
Oh, that's a good point. I didn't see the panicked controlled the return status a few lines below. hmm, is there a specific reason panicked
is set last in that function that I'm missing? Could we just move it to the first thing to do in that function, and then if p is http.ErrAbortHandler
return out of that function?
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.
@shade34321 Code LGTM now. Could you add a test case please?
Please also make sure to sign the CLA (see #3575 (comment)).
Yeah, I've been looking at server_test.go since yesterday trying to understand it a bit more before adding. |
2932240
to
c5501cf
Compare
The tests passing locally for me. I'm a bit unsure if I did the tests right, I feel like I'm missing something.
|
I had to amend my commits, I signed the CLA with the email associated with this account but forgot to set that correctly in my local git repo. It should be fixed now. |
http3/server_test.go
Outdated
@@ -201,6 +201,36 @@ var _ = Describe("Server", func() { | |||
Expect(hfs).To(HaveKeyWithValue(":status", []string{"200"})) | |||
}) | |||
|
|||
It("handles aborts", func() { |
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.
This was just a simple test that I'm not 100% sure is testing what is needed to be tested. But it does test part IMHO.
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 test below this should be sufficient.
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.
Cool, thanks!
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.
Can you remove this one?
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.
Done.
It("handles a aborting handler", func() { | ||
s.Handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
panic(http.ErrAbortHandler) | ||
}) |
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.
This is supposed to be the more complete test, I wasn't sure how to mock an http abort and this is all I could think of. Is there something better?
I think all that is left for me is the circleci stuff, I'll try and take a look some tomorrow though I don't know if it's failing because of my change. When I ran the tests earlier off master it also failed.
|
Don't worry about the datagram test, it's been flaky for a while. |
Codecov ReportBase: 85.50% // Head: 85.51% // Increases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## master #3575 +/- ##
=======================================
Coverage 85.50% 85.51%
=======================================
Files 139 139
Lines 10244 10246 +2
=======================================
+ Hits 8759 8761 +2
Misses 1103 1103
Partials 382 382
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
Thanks for all of the help! I mentioned in the issue that I was working on this for hacktoberfest. Is it possible to have this project opt in so I can receive credit for it please. Thanks! |
I don't have the permissions on this repo. @lucas-clemente, can you help us here? |
I think all that is needed is adding the label to the PR |
That I can do. |
Thank you for the fix, Marten! |
Adds in the
ErrAbortHandler
and checks for later as the stdlib does. Not sure if this is complete though.Fixes #3572