Skip to content

Commit 51b7016

Browse files
committed
errorgroup: fix setLimit cause goroutine leak
1 parent 0de741c commit 51b7016

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

errgroup/errgroup.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,12 @@ func (g *Group) TryGo(f func() error) bool {
121121
//
122122
// The limit must not be modified while any goroutines in the group are active.
123123
func (g *Group) SetLimit(n int) {
124+
if len(g.sem) != 0 {
125+
panic(fmt.Errorf("errgroup: modify limit while %v goroutines in the group are still active", len(g.sem)))
126+
}
124127
if n < 0 {
125128
g.sem = nil
126129
return
127130
}
128-
if len(g.sem) != 0 {
129-
panic(fmt.Errorf("errgroup: modify limit while %v goroutines in the group are still active", len(g.sem)))
130-
}
131131
g.sem = make(chan token, n)
132132
}

0 commit comments

Comments
 (0)