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
compress/gzip: When using gzip with http handlers, panics can't write headers #16830
Comments
I don't see how this is a problem. The panic rules, defer rules, and HTTP ServeHTTP rules (around headers, content-type sniffing, flushing) are all clearly defined, and nothing precludes all these features from being used together. This also isn't a recent change as far as I know. |
Here is a snippet : https://play.golang.org/p/3hPGBmN5V8
To me it was clear that ServeHTTP recovered panics and wrote 500 errors. May be I misread something. This behavior changed to me, I guess. |
I would need to see code too, not just your curl output. And if it changed, when did it change? |
Follow the link ! :) Or here it is :
It changed when I started using 1.7 sorry I didn't mention that ... |
In fact even a simple handler that panics :
Gets me an empty response, may be bananas are too slipery Edit: installed go from brew :
|
From what version? The code you reference is not new at all:
And there's no interesting diff from Go 1.6 to Go 1.7 or even from Go 1.5 to Go 1.7. So, nothing to do here. This behavior has been unmodified for quite some time. People writing gzip http.Handlers will have to deal with panics. |
On gzip handling: On the http server recovering panic: Lessons learned: don't expect anything. Here is an interesting snippet containing all that wrongitude that behaves exactly the same on 1.6 & 1.7:
|
Hello there,
Since this :
go/src/compress/gzip/gzip.go
Line 235 in d0e8d3a
For a lot of libraries that use defer close to Close gzip in http handlers it's going to be impossible to call WriteHeader in the event of a panic, this a call to Write will default the headers to 200.
Found it there : https://github.com/BakedSoftware/go-parameters/pull/6/files
And there : nytimes/gziphandler#15
This issue is just here to warn you guys up.
It would be nice to find a way to warn all the other libs etc.
Cheers !
A.
The text was updated successfully, but these errors were encountered: