rafthttp: always cancel in-flight request when pipeline.send

This fits the way for go1.5 to cancel request.
This commit is contained in:
Yicheng Qin
2015-08-24 10:33:21 -07:00
parent 27b9963959
commit 61a75b3d48
4 changed files with 75 additions and 19 deletions

View File

@ -223,18 +223,6 @@ func newRoundTripperBlocker() *roundTripperBlocker {
cancel: make(map[*http.Request]chan struct{}),
}
}
func (t *roundTripperBlocker) RoundTrip(req *http.Request) (*http.Response, error) {
c := make(chan struct{}, 1)
t.mu.Lock()
t.cancel[req] = c
t.mu.Unlock()
select {
case <-t.unblockc:
return &http.Response{StatusCode: http.StatusNoContent, Body: &nopReadCloser{}}, nil
case <-c:
return nil, errors.New("request canceled")
}
}
func (t *roundTripperBlocker) unblock() {
close(t.unblockc)
}