From a7efc7bd17ef4f790225b450b350cd74501738f6 Mon Sep 17 00:00:00 2001 From: Cuong Manh Le Date: Fri, 30 Sep 2022 10:24:28 +0700 Subject: [PATCH] util/singleflight: sync with upstream Sync with golang.org/x/sync/singleflight at commit 8fcdb60fdcc0539c5e357b2308249e4e752147f1 Fixes #5790 Signed-off-by: Cuong Manh Le --- util/singleflight/singleflight.go | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/util/singleflight/singleflight.go b/util/singleflight/singleflight.go index 88a9c5802..b823b0b15 100644 --- a/util/singleflight/singleflight.go +++ b/util/singleflight/singleflight.go @@ -65,10 +65,6 @@ type call[V any] struct { val V err error - // forgotten indicates whether Forget was called with this call's key - // while the call was still in flight. - forgotten bool - // These fields are read and written with the singleflight // mutex held before the WaitGroup is done, and are read but // not written after the WaitGroup is done. @@ -161,10 +157,10 @@ func (g *Group[K, V]) doCall(c *call[V], key K, fn func() (V, error)) { c.err = errGoexit } - c.wg.Done() g.mu.Lock() defer g.mu.Unlock() - if !c.forgotten { + c.wg.Done() + if g.m[key] == c { delete(g.m, key) } @@ -217,9 +213,6 @@ func (g *Group[K, V]) doCall(c *call[V], key K, fn func() (V, error)) { // an earlier call to complete. func (g *Group[K, V]) Forget(key K) { g.mu.Lock() - if c, ok := g.m[key]; ok { - c.forgotten = true - } delete(g.m, key) g.mu.Unlock() }