Skip to content

Commit cedda3a

Browse files
committed
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. 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]>
1 parent e81a3d9 commit cedda3a

File tree

4 files changed

+520
-556
lines changed

4 files changed

+520
-556
lines changed

http2/client_conn_pool.go

+1
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

+11
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)