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
net/http: panic in net/http.(*chunkWriter).Write via bufio.Writer #61172
Comments
Adding more context here. // Router is defined here func AddUrl(group *gin.RouterGroup) { group.GET("/endpoint", endpointHandlerChain()...) } // handler chain is called func endpointHandlerChain() gin.HandlersChain { return gin.HandlersChain{ getController(someApiHandler), } } // This calls handler and then calls Flush through gin context. func getController(handler func(http.ResponseWriter, *http.Request)) gin.HandlerFunc { return func(c *gin.Context) { handler(c.Writer, c.Request) // This is the handler which is called and it calls io.Copy() c.Writer.Flush() } } // This is the actual handler being called func SomeApiHandler(w http.ResponseWriter, _ *http.Request) { resp := getResp() io.Copy(w, resp.Body) // io.Copy used } Please tell if more information is required. |
@seankhliao Added more context. Please tell if more information is needed. |
UPDATE: panic: runtime error: slice bounds out of range [4586:4096] [recovered] |
According to that stack trace, the panic is happening in
|
Yeah my bad I will change the heading. The slicing operation is happening here One is recovering while other is not. |
The The sites of the two panics are both places involving I suggest building the binary with |
About recover. We already have panic handlers running but from stacktrace I can see there is no mention of our actual application files. Since application is crashing then its probably in a different routine. So I think maybe we cant use recover here.
Will add this and check. Thanks! |
Hi @bcmills It seems it was a race condition. At some place of code we were using fmt.Fprint(w io.Writer, a ...any) concurrently. Thanks for the insights! |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Not reproducable
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Recently we did 2 things in our production application.
Our use case for this function is basically we are getting response from some api.
It is a json response and the size of json can be very big (30MB to 50MB).
So instead of doing io.ReadAll and then json.Unmarshal and then sending bytes through writer we are
directly copying the response.Body to writer. This helps in saving CPU.
Here is the panic. Please note the panic was copied line by line from
AWS Cloudwatch so ordering may not be accurate for stacktrace.
What did you expect to see?
We expected this panic to be caught so that application wont be down.
This is the first time we have seen this panic.
What did you see instead?
This panic is not caught and hence not recovered and our application crashed.
The text was updated successfully, but these errors were encountered: