Skip to content

Commit 1760f31

Browse files
neilddmitshur
authored andcommitted
[internal-branch.go1.16-vendor] http2: refactor request write flow
Move the entire request write into a new writeRequest function, which runs as its own goroutine. The writeRequest function handles all indefintely-blocking operations (in particular, network writes), as well as all post-request cleanup: Closing the request body, sending a RST_STREAM when necessary, releasing the concurrency slot held by the stream, etc. Consolidates several goroutines used to wait for stream slots, write the body, and close response bodies. Ensures that RoundTrip does not block past request cancelation. Updates golang/go#49076 Change-Id: Iaf8bb3e17de89384b031ec4f324918b5720f5877 Reviewed-on: https://go-review.googlesource.com/c/net/+/353390 Trust: Damien Neil <[email protected]> Trust: Brad Fitzpatrick <[email protected]> Run-TryBot: Damien Neil <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]> Reviewed-on: https://go-review.googlesource.com/c/net/+/356988 Reviewed-by: Dmitri Shuralyov <[email protected]>
1 parent 6e87631 commit 1760f31

File tree

4 files changed

+516
-553
lines changed

4 files changed

+516
-553
lines changed

http2/client_conn_pool.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ func (p *clientConnPool) shouldTraceGetConn(cc *ClientConn) bool {
8484
}
8585

8686
func (p *clientConnPool) getClientConn(req *http.Request, addr string, dialOnMiss bool) (*ClientConn, error) {
87+
// TODO(dneil): Dial a new connection when t.DisableKeepAlives is set?
8788
if isConnectionCloseRequest(req) && dialOnMiss {
8889
// It gets its own connection.
8990
traceGetConn(req, addr)

http2/pipe.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,17 @@ type pipeBuffer interface {
3030
io.Reader
3131
}
3232

33+
// setBuffer initializes the pipe buffer.
34+
// It has no effect if the pipe is already closed.
35+
func (p *pipe) setBuffer(b pipeBuffer) {
36+
p.mu.Lock()
37+
defer p.mu.Unlock()
38+
if p.err != nil || p.breakErr != nil {
39+
return
40+
}
41+
p.b = b
42+
}
43+
3344
func (p *pipe) Len() int {
3445
p.mu.Lock()
3546
defer p.mu.Unlock()

0 commit comments

Comments
 (0)