bug: recovery middleware has a bug
Author: pjebsCreated Oct 19, 2022Updated Jul 31, 2026
Labelsbug
There is a comment here regarding https://github.com/urfave/negroni/blob/master/recovery.go#L160:
https://github.com/maruel/panicparse/issues/81#issuecomment-1284620756
As a matter of fact, the code you pointed to in recovery.go is functionally wrong. The only way it could be done is if it were buffering a temporary http.ResponseWriter, and only flushing it when the handler returned. The current code will fail at line 161 as WriteHeader() will ignore the status if data was already written (that's how HTTP works) and the stack data will just be appended to whatever was already streamed to the user. That's bad.
Source: urfave/negroni