]> Cypherpunks repositories - gostls13.git/commit
internal/singleflight: avoid race between multiple Do calls
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Thu, 29 Sep 2022 04:45:33 +0000 (11:45 +0700)
committerGopher Robot <gobot@golang.org>
Fri, 30 Sep 2022 20:49:56 +0000 (20:49 +0000)
commitaeedb5ab13a677367be8e526cc43aeecc3734c86
tree5386eeee3a1f743745d8afa573c0233cdcfcc1ca
parent1e65fa58c11b78bd0b026583e9ba7f724a84d628
internal/singleflight: avoid race between multiple Do calls

When the first call to Do finished, it calls c.wg.Done() to signal
others that the call was done. However, that happens without holding
a lock, so if others call to Do complete and be followed by a call to
ForgotUnshared, that then returns false.

Fixing this by moving c.wg.Done() inside the section guarded by g.mu, so
the two operations won't be interrupted.

Thanks bcmills@ for finding and suggesting fix.

Change-Id: I850f5eb3f9751a0aaa65624d4109aeeb59dee42c
Reviewed-on: https://go-review.googlesource.com/c/go/+/436437
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
src/internal/singleflight/singleflight.go
src/internal/singleflight/singleflight_test.go