[sync] singleflight: Add lazy map init to Forget

32 views
Skip to first unread message

Gerrit Bot (Gerrit)

unread,
Jul 16, 2022, 1:04:26 AM7/16/22
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Gerrit Bot has uploaded this change for review.

View Change

singleflight: Add lazy map init to Forget

Forget is missing lazy map initialization. If Forget is called before
any other method it will panic.

Change-Id: I04dbb0a9edee5e8d35e5497389e765d747be6a7b
GitHub-Last-Rev: 118db8f47bf75498e919e074a2aed3d5ad0e6fa0
GitHub-Pull-Request: golang/sync#16
---
M singleflight/singleflight.go
M singleflight/singleflight_test.go
2 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/singleflight/singleflight.go b/singleflight/singleflight.go
index 690eb85..8306b8b 100644
--- a/singleflight/singleflight.go
+++ b/singleflight/singleflight.go
@@ -204,6 +204,9 @@
// an earlier call to complete.
func (g *Group) Forget(key string) {
g.mu.Lock()
+ if g.m == nil {
+ g.m = make(map[string]*call)
+ }
if c, ok := g.m[key]; ok {
c.forgotten = true
}
diff --git a/singleflight/singleflight_test.go b/singleflight/singleflight_test.go
index 3e51203..6a9a4e9 100644
--- a/singleflight/singleflight_test.go
+++ b/singleflight/singleflight_test.go
@@ -318,3 +318,8 @@
t.Errorf("Test subprocess failed, but the crash isn't caused by panicking in Do")
}
}
+
+func TestForgetEarly(t *testing.T) {
+ var g Group
+ g.Forget("key") // calling Forget before Do/DoChan should not panic
+}

To view, visit change 417894. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: sync
Gerrit-Branch: master
Gerrit-Change-Id: I04dbb0a9edee5e8d35e5497389e765d747be6a7b
Gerrit-Change-Number: 417894
Gerrit-PatchSet: 1
Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
Gerrit-MessageType: newchange

Gerrit Bot (Gerrit)

unread,
Jul 16, 2022, 1:08:25 AM7/16/22
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Gerrit Bot uploaded patch set #2 to this change.

View Change

singleflight: Add lazy map init to Forget

Forget is missing lazy map initialization. If Forget is called before
any other method it will panic.

Change-Id: I04dbb0a9edee5e8d35e5497389e765d747be6a7b
GitHub-Last-Rev: 667518ffb9fb1e217af7b1ec84953f7774bc97f7

GitHub-Pull-Request: golang/sync#16
---
M singleflight/singleflight.go
M singleflight/singleflight_test.go
2 files changed, 22 insertions(+), 0 deletions(-)

To view, visit change 417894. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: sync
Gerrit-Branch: master
Gerrit-Change-Id: I04dbb0a9edee5e8d35e5497389e765d747be6a7b
Gerrit-Change-Number: 417894
Gerrit-PatchSet: 2
Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
Gerrit-MessageType: newpatchset

Gerrit Bot (Gerrit)

unread,
Jul 16, 2022, 1:12:20 AM7/16/22
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Gerrit Bot uploaded patch set #3 to this change.

View Change

singleflight: Add lazy map init to Forget

Change-Id: I04dbb0a9edee5e8d35e5497389e765d747be6a7b
GitHub-Last-Rev: 667518ffb9fb1e217af7b1ec84953f7774bc97f7
GitHub-Pull-Request: golang/sync#16
---
M singleflight/singleflight.go
M singleflight/singleflight_test.go
2 files changed, 19 insertions(+), 0 deletions(-)

To view, visit change 417894. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: sync
Gerrit-Branch: master
Gerrit-Change-Id: I04dbb0a9edee5e8d35e5497389e765d747be6a7b
Gerrit-Change-Number: 417894
Gerrit-PatchSet: 3

Gopher Robot (Gerrit)

unread,
Jul 16, 2022, 1:16:12 AM7/16/22
to Gerrit Bot, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Gopher Robot abandoned this change.

View Change

Abandoned GitHub PR golang/sync#16 has been closed.

To view, visit change 417894. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: sync
Gerrit-Branch: master
Gerrit-Change-Id: I04dbb0a9edee5e8d35e5497389e765d747be6a7b
Gerrit-Change-Number: 417894
Gerrit-PatchSet: 3
Gerrit-Owner: Gerrit Bot <letsus...@gmail.com>
Gerrit-MessageType: abandon
Reply all
Reply to author
Forward
0 new messages