Skip to content

Commit

Permalink
[internal-branch.go1.17-vendor] http2: refactor request write flow
Browse files Browse the repository at this point in the history
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#49077

Change-Id: Iaf8bb3e17de89384b031ec4f324918b5720f5877
Reviewed-on: https://go-review.googlesource.com/c/net/+/353390
Trust: Damien Neil <dneil@google.com>
Trust: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-on: https://go-review.googlesource.com/c/net/+/357683
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
  • Loading branch information
neild authored and dmitshur committed Oct 29, 2021
1 parent a4693d5 commit d6a7866
Show file tree
Hide file tree
Showing 4 changed files with 516 additions and 553 deletions.
1 change: 1 addition & 0 deletions client_conn_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func (p *clientConnPool) shouldTraceGetConn(cc *ClientConn) bool {
}

func (p *clientConnPool) getClientConn(req *http.Request, addr string, dialOnMiss bool) (*ClientConn, error) {
// TODO(dneil): Dial a new connection when t.DisableKeepAlives is set?
if isConnectionCloseRequest(req) && dialOnMiss {
// It gets its own connection.
traceGetConn(req, addr)
Expand Down
11 changes: 11 additions & 0 deletions pipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ type pipeBuffer interface {
io.Reader
}

// setBuffer initializes the pipe buffer.
// It has no effect if the pipe is already closed.
func (p *pipe) setBuffer(b pipeBuffer) {
p.mu.Lock()
defer p.mu.Unlock()
if p.err != nil || p.breakErr != nil {
return
}
p.b = b
}

func (p *pipe) Len() int {
p.mu.Lock()
defer p.mu.Unlock()
Expand Down
Loading

0 comments on commit d6a7866

Please sign in to comment.