diff options
author | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2021-08-12 20:22:27 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2021-08-12 20:22:27 +0000 |
commit | 4d3cc84774549d26e52cbba3a0ffc50d3ede80d5 (patch) | |
tree | de3466e3b835e2c18fa03548ddf0619f5555575b /src/net/http/httputil/reverseproxy.go | |
parent | 7e9f911ec4fd08ce9b4296f0aea4864b53064573 (diff) | |
parent | a64ab8d3ecb38e10007e136edc9dc3abde873e1e (diff) | |
download | go-4d3cc84774549d26e52cbba3a0ffc50d3ede80d5.tar.gz go-4d3cc84774549d26e52cbba3a0ffc50d3ede80d5.zip |
Merge "[dev.typeparams] all: merge master (46fd547) into dev.typeparams" into dev.typeparamsdev.typeparams
Diffstat (limited to 'src/net/http/httputil/reverseproxy.go')
-rw-r--r-- | src/net/http/httputil/reverseproxy.go | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/net/http/httputil/reverseproxy.go b/src/net/http/httputil/reverseproxy.go index 5d39955d62..8b63368386 100644 --- a/src/net/http/httputil/reverseproxy.go +++ b/src/net/http/httputil/reverseproxy.go @@ -235,6 +235,15 @@ func (p *ReverseProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) { if req.ContentLength == 0 { outreq.Body = nil // Issue 16036: nil Body for http.Transport retries } + if outreq.Body != nil { + // Reading from the request body after returning from a handler is not + // allowed, and the RoundTrip goroutine that reads the Body can outlive + // this handler. This can lead to a crash if the handler panics (see + // Issue 46866). Although calling Close doesn't guarantee there isn't + // any Read in flight after the handle returns, in practice it's safe to + // read after closing it. + defer outreq.Body.Close() + } if outreq.Header == nil { outreq.Header = make(http.Header) // Issue 33142: historical behavior was to always allocate } |