Skip to content
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

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
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
18 changes: 18 additions & 0 deletions http2/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -1444,8 +1444,26 @@ 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.mu.Lock()
cc.doNotReuse = true
cc.mu.Unlock()
}
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.mu.Lock()
cc.doNotReuse = true
cc.mu.Unlock()
}
return ctx.Err()
case <-cs.reqCancel:
return errRequestCanceled
Expand Down