Fix goroutine leaks in refs.go
Description: This addresses one of the listed problem files in #4414. I chose to keep the return statement outside of the select statement on line 132 since that behavior was already there following the write to out. License: MIT Signed-off-by: John Forstmeier <john.forstmeier@gmail.com>
forstmeier committed
May 14, 2018 at 15:38 UTC
20b06c297cb5210730b765ca3502d6b998f39350
1 file changed
+9
-2
core/commands/refs.go
+9
-2
@@ -129,7 +129,10 @@ NOTE: List all references recursively by using the flag '-r'.
129
130
for _, o := range objs {
131
if _, err := rw.WriteRefs(o); err != nil {
132
- out <- &RefWrapper{Err: err.Error()}
132
+ select {
133
+ case out <- &RefWrapper{Err: err.Error()}:
134
+ case <-ctx.Done():
135
+ }
136
return
137
}
138
}
@@ -169,7 +172,11 @@ Displays the hashes of all local objects.
172
defer close(out)
173
174
for k := range allKeys {
172
- out <- &RefWrapper{Ref: k.String()}
175
+ select {
176
+ case out <- &RefWrapper{Ref: k.String()}:
177
+ case <-req.Context().Done():
178
+ return
179
+ }
180
}
181
}()
182
},