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

Recover from panic in body write #687

Merged

Conversation

Bobochka
Copy link
Contributor

@Bobochka Bobochka commented Nov 3, 2019

Possibly a successor of #646.
Went as per @erikdubbelboer suggestion (if I understood it correctly). If the general idea is acceptable, will add tests.
Thanks.

Copy link
Collaborator

@erikdubbelboer erikdubbelboer left a comment

Choose a reason for hiding this comment

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

This looks good yes, please add a test.

server.go Outdated
@@ -2219,6 +2219,11 @@ func writeResponse(ctx *RequestCtx, w *bufio.Writer) error {
panic("BUG: cannot write timed out response")
}
err := ctx.Response.Write(w)
if err != nil {
if panicErr, ok := err.(*ErrBodyStreamWritePanic); ok {
ctx.logger.Printf("panic while writing response: %s", panicErr.Error())
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think its necessary to log this here. The error will go all the way up to workerpool.go#L230 where it will be logged anyways.

@Bobochka
Copy link
Contributor Author

Bobochka commented Nov 3, 2019

@erikdubbelboer done.

Unfortunately this doesn't cover SetBodyStreamWriter as writer invocation happens in another goroutine.

@erikdubbelboer
Copy link
Collaborator

I think we can catch the SetBodyStreamWriter as well if we do a similar trick as io.PipeWriter.CloseWithError(). But this will be a bit complicated as fasthttputil.NewPipeConns() deals with net.Conn and not some interface we can just add CloseWithError() to.

So lets save that for another pull request.

@erikdubbelboer erikdubbelboer merged commit 70223a1 into valyala:master Nov 6, 2019
@edoshor edoshor mentioned this pull request Mar 17, 2020
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.

2 participants