[go] net/http/internal/http2: responseWriterState.snapHeader not use deepcopy

3 views
Skip to first unread message

qiu laidongfeng (Gerrit)

unread,
Aug 6, 2026, 2:02:28 AM (4 days ago) Aug 6
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

qiu laidongfeng has uploaded the change for review

Commit message

net/http/internal/http2: responseWriterState.snapHeader not use deepcopy

snapHeader may call delete,
rendering the key no longer usable for query the corresponding value,
yet the value itself remains unmodified.

goos: windows
goarch: amd64
pkg: net/http
cpu: AMD Ryzen 7 7840HS w/ Radeon 780M Graphics
│ new │ new2 │
│ sec/op │ sec/op vs base │
SnapHeaderH2-16 134.1µ ± 3% 133.6µ ± 2% ~ (p=0.739 n=10)

│ new │ new2 │
│ B/op │ B/op vs base │
SnapHeaderH2-16 8.952Ki ± 0% 8.780Ki ± 0% -1.92% (p=0.000 n=10)

│ new │ new2 │
│ allocs/op │ allocs/op vs base │
SnapHeaderH2-16 101.00 ± 0% 91.00 ± 0% -9.90% (p=0.000 n=10)
Change-Id: Ie0338a08a41139a0f118f2f0728aa08b2e64731c

Change diff

diff --git a/src/net/http/internal/http2/server.go b/src/net/http/internal/http2/server.go
index 827d217..d49ccd9 100644
--- a/src/net/http/internal/http2/server.go
+++ b/src/net/http/internal/http2/server.go
@@ -2901,7 +2901,7 @@
rws.wroteHeader = true
rws.status = code
if len(rws.handlerHeader) > 0 {
- rws.snapHeader = cloneHeader(rws.handlerHeader)
+ rws.snapHeader = cloneHeader2(rws.handlerHeader)
}
}

@@ -2919,6 +2919,14 @@
return h2
}

+func cloneHeader2(h Header) Header {
+ h2 := headerPool.Get().(Header)
+ for k, vv := range h {
+ h2[k] = vv
+ }
+ return h2
+}
+
// The Life Of A Write is like this:
//
// * Handler calls w.Write or w.WriteString ->

Change information

Files:
  • M src/net/http/internal/http2/server.go
Change size: S
Delta: 1 file changed, 9 insertions(+), 1 deletion(-)
Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newchange
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Ie0338a08a41139a0f118f2f0728aa08b2e64731c
Gerrit-Change-Number: 811241
Gerrit-PatchSet: 1
Gerrit-Owner: qiu laidongfeng <26454...@qq.com>
Gerrit-Reviewer: qiu laidongfeng <26454...@qq.com>
unsatisfied_requirement
satisfied_requirement
open
diffy

qiu laidongfeng (Gerrit)

unread,
3:23 AM (3 hours ago) 3:23 AM
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
Attention needed from Damien Neil and Nicholas Husin

qiu laidongfeng uploaded new patchset

qiu laidongfeng uploaded patch set #2 to this change.
Following approvals got outdated and were removed:
Open in Gerrit

Related details

Attention is currently required from:
  • Damien Neil
  • Nicholas Husin
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newpatchset
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Ie0338a08a41139a0f118f2f0728aa08b2e64731c
Gerrit-Change-Number: 811241
Gerrit-PatchSet: 2
Gerrit-Owner: qiu laidongfeng <26454...@qq.com>
Gerrit-Reviewer: Damien Neil <dn...@google.com>
Gerrit-Reviewer: Nicholas Husin <n...@golang.org>
Gerrit-Reviewer: qiu laidongfeng <26454...@qq.com>
Gerrit-CC: Gopher Robot <go...@golang.org>
Gerrit-CC: Russ Cox <r...@golang.org>
Gerrit-Attention: Damien Neil <dn...@google.com>
Gerrit-Attention: Nicholas Husin <n...@golang.org>
unsatisfied_requirement
satisfied_requirement
open
diffy

qiu laidongfeng (Gerrit)

unread,
3:24 AM (3 hours ago) 3:24 AM
to goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, Damien Neil, Nicholas Husin, Russ Cox, Gopher Robot, golang-co...@googlegroups.com
Attention needed from Damien Neil and Nicholas Husin

qiu laidongfeng voted Commit-Queue+1

Commit-Queue+1
Open in Gerrit

Related details

Attention is currently required from:
  • Damien Neil
  • Nicholas Husin
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Ie0338a08a41139a0f118f2f0728aa08b2e64731c
Gerrit-Change-Number: 811241
Gerrit-PatchSet: 2
Gerrit-Owner: qiu laidongfeng <26454...@qq.com>
Gerrit-Reviewer: Damien Neil <dn...@google.com>
Gerrit-Reviewer: Nicholas Husin <n...@golang.org>
Gerrit-Reviewer: qiu laidongfeng <26454...@qq.com>
Gerrit-CC: Gopher Robot <go...@golang.org>
Gerrit-CC: Russ Cox <r...@golang.org>
Gerrit-Attention: Damien Neil <dn...@google.com>
Gerrit-Attention: Nicholas Husin <n...@golang.org>
Gerrit-Comment-Date: Mon, 10 Aug 2026 07:24:07 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
unsatisfied_requirement
satisfied_requirement
open
diffy
Reply all
Reply to author
Forward
0 new messages