[go] net/http: prevent server from draining request body if status 100 was not sent

6 views
Skip to first unread message

Nicholas Husin (Gerrit)

unread,
Jun 22, 2026, 5:33:02 PM (5 days ago) Jun 22
to goph...@pubsubhelper.golang.org, Damien Neil, golang...@luci-project-accounts.iam.gserviceaccount.com, golang-co...@googlegroups.com
Attention needed from Damien Neil

New activity on the change

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: comment
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Ice63b2fadfc2a72b825fb97975a2bd116a6a6964
Gerrit-Change-Number: 793160
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>
Gerrit-Comment-Date: Mon, 22 Jun 2026 21:32:56 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: No
unsatisfied_requirement
satisfied_requirement
open
diffy

Nicholas Husin (Gerrit)

unread,
Jun 23, 2026, 4:46:39 PM (4 days ago) Jun 23
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
Attention needed from Damien Neil

Nicholas Husin uploaded new patchset

Nicholas Husin 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
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: Ice63b2fadfc2a72b825fb97975a2bd116a6a6964
Gerrit-Change-Number: 793160
Gerrit-PatchSet: 2
Gerrit-Owner: Nicholas Husin <n...@golang.org>
Gerrit-Reviewer: Damien Neil <dn...@google.com>
Gerrit-Reviewer: Nicholas Husin <n...@golang.org>
unsatisfied_requirement
satisfied_requirement
open
diffy

Nicholas Husin (Gerrit)

unread,
Jun 24, 2026, 4:16:39 PM (3 days ago) Jun 24
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
Attention needed from Damien Neil

Nicholas Husin uploaded new patchset

Nicholas Husin uploaded patch set #3 to this change.
Following approvals got outdated and were removed:
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: newpatchset
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Ice63b2fadfc2a72b825fb97975a2bd116a6a6964
Gerrit-Change-Number: 793160
Gerrit-PatchSet: 3
unsatisfied_requirement
satisfied_requirement
open
diffy

Nicholas Husin (Gerrit)

unread,
Jun 24, 2026, 4:23:18 PM (3 days ago) Jun 24
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
Attention needed from Damien Neil and Nicholas Husin

Nicholas Husin uploaded new patchset

Nicholas Husin uploaded patch set #4 to this change.
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: Ice63b2fadfc2a72b825fb97975a2bd116a6a6964
Gerrit-Change-Number: 793160
Gerrit-PatchSet: 4
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>
Gerrit-Attention: Nicholas Husin <n...@golang.org>
unsatisfied_requirement
satisfied_requirement
open
diffy

Damien Neil (Gerrit)

unread,
Jun 25, 2026, 3:58:26 PM (2 days ago) Jun 25
to Nicholas Husin, goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, golang-co...@googlegroups.com
Attention needed from Nicholas Husin

Damien Neil added 3 comments

File src/net/http/server.go
Line 585, Patchset 4 (Latest): w.closeAfterReply = true
Damien Neil . unresolved

Can this be overwritten by chunkWriter.writeHeader? I might be following this wrong, but I think if you call WriteHeader(200) we set w.closeAfterReply here (but the header is not written, merely buffered), and then if you call Write later writeHeader can overwrite it.

If so, I think the simpler thing might be to add another bool to response indicating whether we've written a 100-Continue, and then have response.shouldReuseConnection take it into account. Might be simplest as a response.wantsContinue, set by conn.serve at the same time it initializes canWriteContinue, and unset if we ever send a 100-Continue.

Line 589, Patchset 4 (Latest): b.mu.Lock()
Damien Neil . unresolved

This is going to deadlock if a body read is happening in another goroutine, which I think can't happen because any body read will have gone through expectContinueReader.Read.

But in the interest of reducing the number of layers we have to think about at once (because I confess this code confuses the heck out of me already), how about we set expectContinueReader.closed instead of body.closed? disableWriteContinue is already synchronizing with it via w.writeContinueMu so we only have one set of locks to think about.

Line 1212, Patchset 4 (Latest): if code < 101 || code > 199 {
Damien Neil . unresolved

Let's make this `code == 100 || code >= 200` while we're touching it, checkWriteHeaderCode will have rejected <100 but the more limited check seems clearer to me. And as a really minor bit of clarity, I think "200 and higher" is a clearer expression of intent than "higher than 199".

Open in Gerrit

Related details

Attention is currently required from:
  • Nicholas Husin
Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement is not 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: go
    Gerrit-Branch: master
    Gerrit-Change-Id: Ice63b2fadfc2a72b825fb97975a2bd116a6a6964
    Gerrit-Change-Number: 793160
    Gerrit-PatchSet: 4
    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: Thu, 25 Jun 2026 19:58:20 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    unsatisfied_requirement
    satisfied_requirement
    open
    diffy

    Nicholas Husin (Gerrit)

    unread,
    Jun 25, 2026, 5:20:17 PM (2 days ago) Jun 25
    to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
    Attention needed from Nicholas Husin

    Nicholas Husin uploaded new patchset

    Nicholas Husin uploaded patch set #5 to this change.
    Following approvals got outdated and were removed:

    Related details

    Attention is currently required from:
    • Nicholas Husin
    Submit Requirements:
      • requirement is not satisfiedCode-Review
      • requirement is not 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: Ice63b2fadfc2a72b825fb97975a2bd116a6a6964
      Gerrit-Change-Number: 793160
      Gerrit-PatchSet: 5
      unsatisfied_requirement
      open
      diffy

      Nicholas Husin (Gerrit)

      unread,
      Jun 25, 2026, 5:22:51 PM (2 days ago) Jun 25
      to goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, Damien Neil, golang-co...@googlegroups.com
      Attention needed from Damien Neil

      Nicholas Husin added 3 comments

      File src/net/http/server.go
      Line 585, Patchset 4: w.closeAfterReply = true
      Damien Neil . resolved

      Can this be overwritten by chunkWriter.writeHeader? I might be following this wrong, but I think if you call WriteHeader(200) we set w.closeAfterReply here (but the header is not written, merely buffered), and then if you call Write later writeHeader can overwrite it.

      If so, I think the simpler thing might be to add another bool to response indicating whether we've written a 100-Continue, and then have response.shouldReuseConnection take it into account. Might be simplest as a response.wantsContinue, set by conn.serve at the same time it initializes canWriteContinue, and unset if we ever send a 100-Continue.

      Nicholas Husin

      I think `chunkWriter.writeHeader` overwriting `w.closeAfterReply` should be impossible. Looking at symbol references, `w.closeAfterReply` can only be set to `false` when [dealing with HTTP/1.0 keep-alive connections](https://cs.opensource.google/go/go/+/master:src/net/http/server.go;l=1360-1365;drc=57f9a589b5dfd9635879e85cd1c2937441368989). `100 Continue` is only supported in HTTP/1.1, so we should be good here.

      Line 589, Patchset 4: b.mu.Lock()
      Damien Neil . resolved

      This is going to deadlock if a body read is happening in another goroutine, which I think can't happen because any body read will have gone through expectContinueReader.Read.

      But in the interest of reducing the number of layers we have to think about at once (because I confess this code confuses the heck out of me already), how about we set expectContinueReader.closed instead of body.closed? disableWriteContinue is already synchronizing with it via w.writeContinueMu so we only have one set of locks to think about.

      Nicholas Husin

      Good idea, thanks, done!

      Also explicitly make this method a noop unless `w.reqBody` is an `expectContinueReader` to hopefully make things clearer.

      Line 1212, Patchset 4: if code < 101 || code > 199 {
      Damien Neil . resolved

      Let's make this `code == 100 || code >= 200` while we're touching it, checkWriteHeaderCode will have rejected <100 but the more limited check seems clearer to me. And as a really minor bit of clarity, I think "200 and higher" is a clearer expression of intent than "higher than 199".

      Nicholas Husin

      Sounds good, done!

      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: comment
        Gerrit-Project: go
        Gerrit-Branch: master
        Gerrit-Change-Id: Ice63b2fadfc2a72b825fb97975a2bd116a6a6964
        Gerrit-Change-Number: 793160
        Gerrit-PatchSet: 5
        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>
        Gerrit-Comment-Date: Thu, 25 Jun 2026 21:22:46 +0000
        Gerrit-HasComments: Yes
        Gerrit-Has-Labels: No
        Comment-In-Reply-To: Damien Neil <dn...@google.com>
        unsatisfied_requirement
        satisfied_requirement
        open
        diffy

        Damien Neil (Gerrit)

        unread,
        Jun 26, 2026, 4:53:37 PM (14 hours ago) Jun 26
        to Nicholas Husin, goph...@pubsubhelper.golang.org, golang...@luci-project-accounts.iam.gserviceaccount.com, 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: go
        Gerrit-Branch: master
        Gerrit-Change-Id: Ice63b2fadfc2a72b825fb97975a2bd116a6a6964
        Gerrit-Change-Number: 793160
        Gerrit-PatchSet: 5
        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: Fri, 26 Jun 2026 20:53:32 +0000
        Gerrit-HasComments: No
        Gerrit-Has-Labels: Yes
        satisfied_requirement
        unsatisfied_requirement
        open
        diffy
        Reply all
        Reply to author
        Forward
        0 new messages