Skip to content

Commit 2a180e2

Browse files
justinmayhewgopherbot
authored andcommitted
errgroup: use consistent read for SetLimit panic
This could produce a confusing panic message if the second len(g.sem) call returns 0. Avoid that by reading it once. Change-Id: Ibdb4963f90921bc20427b3f1e2de410638f6cb6b Reviewed-on: https://go-review.googlesource.com/c/sync/+/726280 Reviewed-by: Alan Donovan <[email protected]> Auto-Submit: Alan Donovan <[email protected]> Reviewed-by: Sean Liao <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]>
1 parent 1966f53 commit 2a180e2

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

errgroup/errgroup.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ func (g *Group) SetLimit(n int) {
144144
g.sem = nil
145145
return
146146
}
147-
if len(g.sem) != 0 {
148-
panic(fmt.Errorf("errgroup: modify limit while %v goroutines in the group are still active", len(g.sem)))
147+
if active := len(g.sem); active != 0 {
148+
panic(fmt.Errorf("errgroup: modify limit while %v goroutines in the group are still active", active))
149149
}
150150
g.sem = make(chan token, n)
151151
}

0 commit comments

Comments
 (0)