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

http3: handle ErrAbortHandler when the handler panics #3575

Merged
merged 6 commits into from Oct 9, 2022

Conversation

shade34321
Copy link
Contributor

Adds in the ErrAbortHandler and checks for later as the stdlib does. Not sure if this is complete though.

Fixes #3572

@google-cla
Copy link

google-cla bot commented Oct 7, 2022

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 {
Copy link
Member

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?

Copy link
Contributor Author

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?

Copy link
Contributor Author

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.

Copy link
Member

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

Copy link
Contributor Author

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?

Copy link
Member

@marten-seemann marten-seemann left a 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)).

@marten-seemann marten-seemann changed the title Handle abort like the stdlib does http3: handle ErrAbortHandler when the handler panics Oct 8, 2022
@shade34321
Copy link
Contributor Author

Yeah, I've been looking at server_test.go since yesterday trying to understand it a bit more before adding.

@shade34321
Copy link
Contributor Author

The tests passing locally for me. I'm a bit unsure if I did the tests right, I feel like I'm missing something.

quic-go/http3 on  http3_handle_abort via 🐹 v1.18 took 9s 
❯ go test
Running Suite: HTTP/3 Suite
===========================
Random Seed: 1665232217
Will run 173 of 173 specs

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ran 173 of 173 Specs in 2.311 seconds
SUCCESS! -- 173 Passed | 0 Failed | 0 Pending | 0 Skipped
PASS
ok      github.com/lucas-clemente/quic-go/http3 5.214s

quic-go/http3 on  http3_handle_abort via 🐹 v1.18 took 6s 
❯ 

@shade34321
Copy link
Contributor Author

@shade34321 Code LGTM now. Could you add a test case please?

Please also make sure to sign the CLA (see #3575 (comment)).

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.

@@ -201,6 +201,36 @@ var _ = Describe("Server", func() {
Expect(hfs).To(HaveKeyWithValue(":status", []string{"200"}))
})

It("handles aborts", func() {
Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cool, thanks!

Copy link
Member

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?

Copy link
Contributor Author

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)
})
Copy link
Contributor Author

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?

@shade34321
Copy link
Contributor Author

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.

Summarizing 1 Failure:

[Fail] Datagram test with QUIC version v1 [It] sends datagrams 
/home/circleci/project/integrationtests/self/datagram_test.go:67

@marten-seemann
Copy link
Member

Don't worry about the datagram test, it's been flaky for a while.

@marten-seemann marten-seemann added this to the v0.30.0 milestone Oct 9, 2022
@codecov
Copy link

codecov bot commented Oct 9, 2022

Codecov Report

Base: 85.50% // Head: 85.51% // Increases project coverage by +0.00% 🎉

Coverage data is based on head (0dd041a) compared to base (424a663).
Patch coverage: 100.00% of modified lines in pull request are covered.

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           
Impacted Files Coverage Δ
http3/server.go 74.45% <100.00%> (+0.16%) ⬆️

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.
📢 Do you have feedback about the report comment? Let us know in this issue.

@shade34321
Copy link
Contributor Author

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!

@marten-seemann
Copy link
Member

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.

I don't have the permissions on this repo. @lucas-clemente, can you help us here?

@shade34321
Copy link
Contributor Author

I think all that is needed is adding the label to the PR hacktoberfest-accepted but I understand if you don't have permission for that. Thanks anyways!

@marten-seemann
Copy link
Member

I think all that is needed is adding the label to the PR hacktoberfest-accepted but I understand if you don't have permission for that.

That I can do.

@mholt
Copy link
Contributor

mholt commented Oct 13, 2022

Thank you for the fix, Marten!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

http3: handle http.ErrAbortHandler in panicking HTTP handlers
3 participants