From 20b06c297cb5210730b765ca3502d6b998f39350 Mon Sep 17 00:00:00 2001 From: forstmeier Date: Mon, 14 May 2018 15:38:13 -0400 Subject: [PATCH] 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 --- core/commands/refs.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/core/commands/refs.go b/core/commands/refs.go index 294ef9bd7..7e61eed2c 100644 --- a/core/commands/refs.go +++ b/core/commands/refs.go @@ -129,7 +129,10 @@ NOTE: List all references recursively by using the flag '-r'. for _, o := range objs { if _, err := rw.WriteRefs(o); err != nil { - out <- &RefWrapper{Err: err.Error()} + select { + case out <- &RefWrapper{Err: err.Error()}: + case <-ctx.Done(): + } return } } @@ -169,7 +172,11 @@ Displays the hashes of all local objects. defer close(out) for k := range allKeys { - out <- &RefWrapper{Ref: k.String()} + select { + case out <- &RefWrapper{Ref: k.String()}: + case <-req.Context().Done(): + return + } } }() },