8000 fix: if the only stream in a connection times out, prevent re-use by btasker · Pull Request #169 · golang/net · GitHub
[go: up one dir, main page]

Skip to content

fix: if the only stream in a connection times out, prevent re-use #169

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
net/http2: if the only stream in a connection times out, prevent re-use
This commit mitigates some raciness which can occur when an established
connection fails. Without it, the connection can continue to be drawn
from the connection pool, leading to subsequent requests failing.

Fixes golang/go#59690
  • Loading branch information
btasker committed Apr 18, 2023
commit 613c39d390d0672bb2e67c5d2266e07491e88582
14 changes: 14 additions & 0 deletions http2/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -1444,8 +1444,22 @@ func (cs *clientStream) writeRequest(req *http.Request) (err error) {
respHeaderRecv = nil
respHeaderTimer = nil // keep waiting for END_STREAM
case <-cs.abort:
// If this was the only active stream, mark the connection
// as not for re-use in order to address raciness if the caller
// tries to call closeIdleConnections() before the stream has been
// removed
if len(cc.streams) == 1 {
cc.doNotReuse = true
}
return cs.abortErr
case <-ctx.Done():
// If this was the only active stream, mark the connection
// as not for re-use in order to address raciness if the caller
// tries to call closeIdleConnections() before the stream has been
// removed
if len(cc.streams) == 1 {
cc.doNotReuse = true
}
return ctx.Err()
case <-cs.reqCancel:
return errRequestCanceled
Expand Down
0