From 5cbe15436894e889bbe52fcade918e208dc5ff42 Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Tue, 25 Jul 2017 15:29:39 -0700 Subject: [PATCH] flightcontrol: better errRetry handling Signed-off-by: Tonis Tiigi --- util/flightcontrol/flightcontrol.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/util/flightcontrol/flightcontrol.go b/util/flightcontrol/flightcontrol.go index 97fd9a76..1dc82458 100644 --- a/util/flightcontrol/flightcontrol.go +++ b/util/flightcontrol/flightcontrol.go @@ -27,6 +27,12 @@ type Group struct { } func (g *Group) Do(ctx context.Context, key string, fn func(ctx context.Context) (interface{}, error)) (v interface{}, err error) { + defer func() { + if errors.Cause(err) == errRetry { + runtime.Gosched() + v, err = g.Do(ctx, key, fn) + } + }() g.mu.Lock() if g.m == nil { g.m = make(map[string]*call) @@ -34,12 +40,7 @@ func (g *Group) Do(ctx context.Context, key string, fn func(ctx context.Context) if c, ok := g.m[key]; ok { // register 2nd waiter g.mu.Unlock() - v, err := c.wait(ctx) - if err == errRetry { - runtime.Gosched() - return g.Do(ctx, key, fn) - } - return v, err + return c.wait(ctx) } c := newCall(fn)