From 29dca49cb5632afab8f8331d82b754bbd84df8a9 Mon Sep 17 00:00:00 2001 From: Yicheng Qin Date: Thu, 11 Jun 2015 09:12:23 -0700 Subject: [PATCH] rafthttp: wait 1ms before enabling cancel CancelRequest only effects on in-flight request, so we need to wait for Do(request) called before enabling cancel. --- rafthttp/pipeline.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/rafthttp/pipeline.go b/rafthttp/pipeline.go index 61840e751..90c63b0c1 100644 --- a/rafthttp/pipeline.go +++ b/rafthttp/pipeline.go @@ -153,6 +153,7 @@ func (p *pipeline) post(data []byte) (err error) { select { case <-done: case <-p.stopc: + waitSchedule() stopped = true if cancel, ok := p.tr.(canceler); ok { cancel.CancelRequest(req) @@ -199,3 +200,6 @@ func (p *pipeline) post(data []byte) (err error) { return fmt.Errorf("unexpected http status %s while posting to %q", http.StatusText(resp.StatusCode), req.URL.String()) } } + +// waitSchedule waits other goroutines to be scheduled for a while +func waitSchedule() { time.Sleep(time.Millisecond) }