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: reset stream when a handler panics #4181

Merged
merged 6 commits into from
Dec 16, 2023

Conversation

WeidiDeng
Copy link
Contributor

When debugging an issue for caddy, I found http3 server handler will not correctly propagate stream error. Code example here.

In this case Content-Length is set, http3 may use that info to infer the stream doesn't terminate properly. But in a streaming environment if there is an error upstream, client should be able to know there is an error at a stream level just like http2 regardless of the presence of Content-Length.

Copy link

codecov bot commented Nov 23, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (771d136) 83.77% compared to head (f8f65c3) 83.74%.
Report is 14 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4181      +/-   ##
==========================================
- Coverage   83.77%   83.74%   -0.04%     
==========================================
  Files         150      150              
  Lines       15425    15475      +50     
==========================================
+ Hits        12922    12958      +36     
- Misses       2006     2019      +13     
- Partials      497      498       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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.

If the panic happens before we've written the HTTP header, should we just write the 500 and close the stream?

@WeidiDeng
Copy link
Contributor Author

I don't think status 500 is necessary in this case. Related pr and issue.

@marten-seemann
Copy link
Member

What does HTTP/2 do in both these cases?

@WeidiDeng
Copy link
Contributor Author

HTTP/2 doesn't differentiate between these two cases. It will reset the stream if there is a panic.

@WeidiDeng
Copy link
Contributor Author

Per http.Handler documentation:

If ServeHTTP panics, the server (the caller of ServeHTTP) assumes that the effect of the panic was isolated to the active request. It recovers the panic, logs a stack trace to the server error log, and either closes the network connection or sends an HTTP/2 RST_STREAM, depending on the HTTP protocol. To abort a handler so the client sees an interrupted response but the server doesn't log an error, panic with the value ErrAbortHandler.

There is no mention of interpreting the panic and handling it the other way. And it's actually doing that.

@marten-seemann marten-seemann added this to the v0.41 milestone Dec 10, 2023
integrationtests/self/http_test.go Outdated Show resolved Hide resolved
http3/frames.go Outdated Show resolved Hide resolved
http3/server_test.go Outdated Show resolved Hide resolved
http3/server_test.go Outdated Show resolved Hide resolved
http3/server_test.go Outdated Show resolved Hide resolved
integrationtests/self/http_test.go Show resolved Hide resolved
@marten-seemann marten-seemann changed the title http3: handler sends stream errors when a panic happened http3: reset stream when a handler panics Dec 16, 2023
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.

Thank you @WeidiDeng, and sorry for the delay in reviewing this PR! This will be part of the next quic-go release.

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

Successfully merging this pull request may close these issues.

None yet

2 participants