]> Cypherpunks repositories - gostls13.git/commit
net/http: do not discard body content when closing it within request handlers
authorNicholas S. Husin <nsh@golang.org>
Fri, 14 Nov 2025 21:11:23 +0000 (16:11 -0500)
committerNicholas Husin <nsh@golang.org>
Fri, 14 Nov 2025 21:32:00 +0000 (13:32 -0800)
commitcb0d9980f5721715ebb73dd2e580eaa11c2ddee2
tree8ab896c3938b34ec18d086bc2afcd5af10cf5dd3
parent03ed43988ff7f7671094d8c455532de7f2242e70
net/http: do not discard body content when closing it within request handlers

(*body).Close() internally tries to discard the content of a request
body up to 256 KB. We rely on this behavior to allow connection re-use,
by calling (*body).Close() when our request handler exits.

Unfortunately, this causes an unfortunate side-effect where we would
prematurely try to discard a body content when (*body).Close() is called
from within a request handler.

There should not be a good reason for (*body).Close() to do this when
called from within a request handler. As such, this CL modifies
(*body).Close() to not discard body contents when called from within a
request handler. Note that when a request handler exits, it will still
try to discard the body content for connection re-use.

For #75933

Change-Id: I71d2431a540579184066dd35d3da49d6c85c3daf
Reviewed-on: https://go-review.googlesource.com/c/go/+/720380
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Nicholas Husin <husin@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
src/net/http/serve_test.go
src/net/http/server.go
src/net/http/transfer.go