[net] internal/http3: fix Write in Server Handler returning the wrong value

2 views
Skip to first unread message

Nicholas Husin (Gerrit)

unread,
Feb 24, 2026, 6:47:47 PM (10 hours ago) Feb 24
to Damien Neil, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
Attention needed from Damien Neil

Nicholas Husin has uploaded the change for review

Nicholas Husin would like Damien Neil to review this change.

Commit message

internal/http3: fix Write in Server Handler returning the wrong value

When changing the approach used in go.dev/cl/746760 (i.e. adjusting
slices, rather than keeping track of active part of the slices in
Write), the return value was unfortunately not updated properly.

This CL fixes the problem and modifies the test to also verify that
Write returns the correct value.

For golang/go#70914
Change-Id: Ic7dda43d47a85c74c03cf02208a0cd461b58dcf2

Change diff

diff --git a/internal/http3/server.go b/internal/http3/server.go
index 6536eab..2501b19 100644
--- a/internal/http3/server.go
+++ b/internal/http3/server.go
@@ -414,11 +414,12 @@
// As a special case, we always want to save b to the buffer even when b is
// big if we had yet to write our header, so we can infer headers like
// "Content-Type" with as much information as possible.
+ initialBLen := len(b)
initialBufLen := len(rw.bb)
if !rw.wroteHeader || len(b) <= cap(rw.bb)-len(rw.bb) {
b = rw.bb.write(b)
if len(b) == 0 {
- return len(b), nil
+ return initialBLen, nil
}
}

@@ -430,13 +431,13 @@
// 3. Reset the current body buffer so it can be used again.
rw.writeHeaderLockedOnce()
if rw.cannotHaveBody {
- return len(b), nil
+ return initialBLen, nil
}
if n, err := rw.bw.write(rw.bb, b); err != nil {
return max(0, n-initialBufLen), err
}
rw.bb.discard()
- return len(b), nil
+ return initialBLen, nil
}

func (rw *responseWriter) Flush() {
diff --git a/internal/http3/server_test.go b/internal/http3/server_test.go
index 0583cf0..a56581b 100644
--- a/internal/http3/server_test.go
+++ b/internal/http3/server_test.go
@@ -755,7 +755,13 @@
ts := newTestServer(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
for n := 0; n < tt.bodyLen; n += tt.writeSize {
data := slices.Repeat([]byte("a"), min(tt.writeSize, tt.bodyLen-n))
- w.Write(data)
+ n, err := w.Write(data)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if n != len(data) {
+ t.Errorf("got %v bytes when writing in server handler, want %v", n, len(data))
+ }
if tt.flushes {
w.(http.Flusher).Flush()
}

Change information

Files:
  • M internal/http3/server.go
  • M internal/http3/server_test.go
Change size: S
Delta: 2 files changed, 11 insertions(+), 4 deletions(-)
Open in Gerrit

Related details

Attention is currently required from:
  • Damien Neil
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: net
Gerrit-Branch: master
Gerrit-Change-Id: Ic7dda43d47a85c74c03cf02208a0cd461b58dcf2
Gerrit-Change-Number: 748680
Gerrit-PatchSet: 1
Gerrit-Owner: Nicholas Husin <n...@golang.org>
Gerrit-Reviewer: Damien Neil <dn...@google.com>
Gerrit-Reviewer: Nicholas Husin <n...@golang.org>
Gerrit-Attention: Damien Neil <dn...@google.com>
unsatisfied_requirement
satisfied_requirement
open
diffy

Damien Neil (Gerrit)

unread,
Feb 24, 2026, 7:00:45 PM (10 hours ago) Feb 24
to Nicholas Husin, goph...@pubsubhelper.golang.org, Go LUCI, golang-co...@googlegroups.com
Attention needed from Nicholas Husin

Damien Neil voted Code-Review+2

Code-Review+2
Open in Gerrit

Related details

Attention is currently required from:
  • Nicholas Husin
Submit Requirements:
  • requirement satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: net
Gerrit-Branch: master
Gerrit-Change-Id: Ic7dda43d47a85c74c03cf02208a0cd461b58dcf2
Gerrit-Change-Number: 748680
Gerrit-PatchSet: 1
Gerrit-Owner: Nicholas Husin <n...@golang.org>
Gerrit-Reviewer: Damien Neil <dn...@google.com>
Gerrit-Reviewer: Nicholas Husin <n...@golang.org>
Gerrit-Attention: Nicholas Husin <n...@golang.org>
Gerrit-Comment-Date: Wed, 25 Feb 2026 00:00:37 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
satisfied_requirement
unsatisfied_requirement
open
diffy

Nicholas Husin (Gerrit)

unread,
Feb 24, 2026, 7:18:50 PM (10 hours ago) Feb 24
to Nicholas Husin, goph...@pubsubhelper.golang.org, Damien Neil, Go LUCI, golang-co...@googlegroups.com
Attention needed from Nicholas Husin

Nicholas Husin voted Code-Review+1

Code-Review+1
Open in Gerrit

Related details

Attention is currently required from:
  • Nicholas Husin
Submit Requirements:
    • requirement satisfiedCode-Review
    • requirement satisfiedNo-Unresolved-Comments
    • requirement satisfiedReview-Enforcement
    • requirement satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: net
    Gerrit-Branch: master
    Gerrit-Change-Id: Ic7dda43d47a85c74c03cf02208a0cd461b58dcf2
    Gerrit-Change-Number: 748680
    Gerrit-PatchSet: 1
    Gerrit-Owner: Nicholas Husin <n...@golang.org>
    Gerrit-Reviewer: Damien Neil <dn...@google.com>
    Gerrit-Reviewer: Nicholas Husin <hu...@google.com>
    Gerrit-Reviewer: Nicholas Husin <n...@golang.org>
    Gerrit-Attention: Nicholas Husin <n...@golang.org>
    Gerrit-Comment-Date: Wed, 25 Feb 2026 00:18:47 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: Yes
    satisfied_requirement
    open
    diffy

    Nicholas Husin (Gerrit)

    unread,
    Feb 24, 2026, 7:19:02 PM (10 hours ago) Feb 24
    to goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, Nicholas Husin, Damien Neil, Go LUCI, golang-co...@googlegroups.com

    Nicholas Husin submitted the change

    Change information

    Commit message:
    internal/http3: fix Write in Server Handler returning the wrong value

    When changing the approach used in go.dev/cl/746760 (i.e. adjusting
    slices, rather than keeping track of active part of the slices in
    Write), the return value was unfortunately not updated properly.

    This CL fixes the problem and modifies the test to also verify that
    Write returns the correct value.

    For golang/go#70914
    Change-Id: Ic7dda43d47a85c74c03cf02208a0cd461b58dcf2
    Reviewed-by: Damien Neil <dn...@google.com>
    Reviewed-by: Nicholas Husin <hu...@google.com>
    Files:
    • M internal/http3/server.go
    • M internal/http3/server_test.go
    Change size: S
    Delta: 2 files changed, 11 insertions(+), 4 deletions(-)
    Branch: refs/heads/master
    Submit Requirements:
    • requirement satisfiedCode-Review: +2 by Damien Neil, +1 by Nicholas Husin
    • requirement satisfiedTryBots-Pass: LUCI-TryBot-Result+1 by Go LUCI
    Open in Gerrit
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: merged
    Gerrit-Project: net
    Gerrit-Branch: master
    Gerrit-Change-Id: Ic7dda43d47a85c74c03cf02208a0cd461b58dcf2
    Gerrit-Change-Number: 748680
    Gerrit-PatchSet: 2
    open
    diffy
    satisfied_requirement
    Reply all
    Reply to author
    Forward
    0 new messages