Skip to content

Commit

Permalink
Fix race condition in Client.DoTimeout
Browse files Browse the repository at this point in the history
  • Loading branch information
erikdubbelboer committed Feb 6, 2021
1 parent 5661df8 commit ed1cedd
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1152,7 +1152,7 @@ func clientDoDeadline(req *Request, resp *Response, deadline time.Time, c client
// usually continue execution on the host.

var mu sync.Mutex
var timedout bool
var timedout, responded bool

go func() {
reqCopy.timeout = timeout
Expand All @@ -1166,6 +1166,7 @@ func clientDoDeadline(req *Request, resp *Response, deadline time.Time, c client
}
swapRequestBody(reqCopy, req)
ch <- errDo
responded = true
}
}
mu.Unlock()
Expand All @@ -1181,8 +1182,12 @@ func clientDoDeadline(req *Request, resp *Response, deadline time.Time, c client
case <-tc.C:
mu.Lock()
{
timedout = true
err = ErrTimeout
if responded {
err = <-ch
} else {
timedout = true
err = ErrTimeout
}
}
mu.Unlock()
}
Expand Down

0 comments on commit ed1cedd

Please sign in to comment.