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: document more how to abort a response from Handlers #17790
Comments
Calling See #16542 (comment) for some background. The docs already say:
I suppose you want a way to do this without the stack trace, though? I thought we had a bug open about that, but I can't find it, so we'll use this one. Thanks for filing. |
Ah, right.
Yes, this is meant to happen when the backend times out, and it's part of -- Juliusz |
I've found that https://play.golang.org/p/96dhROeoTh |
@rhysh, neither of those were intentional. // Run on its own goroutine.
func (sc *serverConn) runHandler(rw *responseWriter, req *http.Request, handler func(http.ResponseWriter, *http.Request)) {
didPanic := true
defer func() {
rw.rws.stream.cancelCtx()
if didPanic {
e := recover()
// Same as net/http:
const size = 64 << 10
buf := make([]byte, size)
buf = buf[:runtime.Stack(buf, false)]
// ...
sc.logf("http2: panic serving %v: %v\n%s", sc.conn.RemoteAddr(), e, buf)
return
}
rw.handlerDone()
}()
handler(rw, req)
didPanic = false
} Likewise, it looks like http2.Server would interpret a I suppose we could make that the official way, though. One one official way. I think I'd prefer to make an explicit panic value, though, so if you're using a different http server hosting http.Handlers and that implementation forgets to do the |
CL https://golang.org/cl/33099 mentions this issue. |
Add an explicit way for Handlers to abort their response to the client and also not spam their error log with stack traces. panic(nil) also worked in the past (for http1 at least), so continue to make that work (and test it). But ErrAbortHandler is more explicit. Updates #17790 (needs http2 updates also) Change-Id: Ib1456905b27e2ae8cf04c0983dc73e314a4a751e Reviewed-on: https://go-review.googlesource.com/33099 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
CL https://golang.org/cl/33102 mentions this issue. |
…et/http Updates golang/go#17790 Change-Id: I7bc596d9a80490d545ad3d1de5859efce34714f6 Reviewed-on: https://go-review.googlesource.com/33102 TryBot-Result: Gobot Gobot <gobot@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
CL https://golang.org/cl/33103 mentions this issue. |
Thanks, Brad.
|
HTTP/1.1 doesn't provide a way to signal an error to the client after we have started writing out a body (not sure about HTTP/2). When serving a chunked reply, an error can only be signaled by interrupting the connection without terminating the chunked framing.
I'm currently doing the following to abort a reply prematurely, which is less than obvious and does nothing useful with HTTP/2:
(This can be tested with curl, which should display "transfer closed with outstanding read data remaining" when this code triggers.)
Please provide an official, documented way to brutally interrupt a reply after the headers have been sent.
The text was updated successfully, but these errors were encountered: