aboutsummaryrefslogtreecommitdiff
path: root/src/net/http/httputil/reverseproxy.go
diff options
context:
space:
mode:
authorDamien Neil <dneil@google.com>2025-03-06 13:24:58 -0800
committerGopher Robot <gobot@golang.org>2025-03-10 08:11:43 -0700
commit22d5d09f1e39bf0ef77bfcf80388c676e7e91574 (patch)
tree0b954411e0ffe53785d642942f315660f2a3e273 /src/net/http/httputil/reverseproxy.go
parentbc5f4a555e933e6861d12edba4c2d87ef6caf8e6 (diff)
downloadgo-22d5d09f1e39bf0ef77bfcf80388c676e7e91574.tar.xz
net/http/httputil: close hijacked connections when CloseWrite not available
CL 637939 changed ReverseProxy's handling of hijacked connections: After copying all data in one direction, it half-closes the outbound connection rather than fully closing both. Revert to the old behavior when the outbound connection does not support CloseWrite, avoiding a case where one side of the proxied connection closes but the other remains open. Fixes #72140 Change-Id: Ic0cacaa6323290f89ba48fd6cae737e86045a435 Reviewed-on: https://go-review.googlesource.com/c/go/+/655595 Reviewed-by: Jonathan Amsterdam <jba@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Damien Neil <dneil@google.com>
Diffstat (limited to 'src/net/http/httputil/reverseproxy.go')
-rw-r--r--src/net/http/httputil/reverseproxy.go11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/net/http/httputil/reverseproxy.go b/src/net/http/httputil/reverseproxy.go
index bbb7c13d41..079d5c86f7 100644
--- a/src/net/http/httputil/reverseproxy.go
+++ b/src/net/http/httputil/reverseproxy.go
@@ -794,16 +794,19 @@ func (p *ReverseProxy) handleUpgradeResponse(rw http.ResponseWriter, req *http.R
go spc.copyToBackend(errc)
go spc.copyFromBackend(errc)
- // wait until both copy functions have sent on the error channel
+ // Wait until both copy functions have sent on the error channel,
+ // or until one fails.
err := <-errc
if err == nil {
err = <-errc
}
- if err != nil {
+ if err != nil && err != errCopyDone {
p.getErrorHandler()(rw, req, fmt.Errorf("can't copy: %v", err))
}
}
+var errCopyDone = errors.New("hijacked connection copy complete")
+
// switchProtocolCopier exists so goroutines proxying data back and
// forth have nice names in stacks.
type switchProtocolCopier struct {
@@ -822,7 +825,7 @@ func (c switchProtocolCopier) copyFromBackend(errc chan<- error) {
return
}
- errc <- nil
+ errc <- errCopyDone
}
func (c switchProtocolCopier) copyToBackend(errc chan<- error) {
@@ -837,7 +840,7 @@ func (c switchProtocolCopier) copyToBackend(errc chan<- error) {
return
}
- errc <- nil
+ errc <- errCopyDone
}
func cleanQueryParams(s string) string {