Skip to content

Commit a630d4f

Browse files
moshegoodianlancetaylor
authored andcommitted
http2: support concurrent Request.Close calls
While no guarantees are made about the safety of repeated or concurrent closes of a request body, HTTP/1 request bodies are concurrency-safe and HTTP/2 ones should be as well. Fixes golang/go#51197 Change-Id: Id6527dc2932579cabc9cbe921c6e0b3b4a3d472c Reviewed-on: https://go-review.googlesource.com/c/net/+/386495 Reviewed-by: Damien Neil <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent 290c469 commit a630d4f

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

http2/server.go

+9-8
Original file line numberDiff line numberDiff line change
@@ -2316,17 +2316,18 @@ type requestBody struct {
23162316
_ incomparable
23172317
stream *stream
23182318
conn *serverConn
2319-
closed bool // for use by Close only
2320-
sawEOF bool // for use by Read only
2321-
pipe *pipe // non-nil if we have a HTTP entity message body
2322-
needsContinue bool // need to send a 100-continue
2319+
closeOnce sync.Once // for use by Close only
2320+
sawEOF bool // for use by Read only
2321+
pipe *pipe // non-nil if we have a HTTP entity message body
2322+
needsContinue bool // need to send a 100-continue
23232323
}
23242324

23252325
func (b *requestBody) Close() error {
2326-
if b.pipe != nil && !b.closed {
2327-
b.pipe.BreakWithError(errClosedBody)
2328-
}
2329-
b.closed = true
2326+
b.closeOnce.Do(func() {
2327+
if b.pipe != nil {
2328+
b.pipe.BreakWithError(errClosedBody)
2329+
}
2330+
})
23302331
return nil
23312332
}
23322333

0 commit comments

Comments
 (0)