From c8a74cb4a463ed7a0802849ca9b08038cd677707 Mon Sep 17 00:00:00 2001 From: D1CED Date: Thu, 18 Feb 2021 16:46:40 +0100 Subject: [PATCH] prevent leaking goroutines --- pkg/vcs/vcs.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/pkg/vcs/vcs.go b/pkg/vcs/vcs.go index dbda8aa9..df662de6 100644 --- a/pkg/vcs/vcs.go +++ b/pkg/vcs/vcs.go @@ -172,12 +172,22 @@ func (v *InfoStore) NeedsUpdate(infos OriginInfoByURL) bool { // if we find an update we use this to exit early and return true hasUpdate := make(chan struct{}) + closed := make(chan struct{}) + defer close(closed) + checkHash := func(url string, info OriginInfo) { hash := v.getCommit(url, info.Branch, info.Protocols) + + var sendTo chan<- struct{} if hash != "" && hash != info.SHA { - hasUpdate <- struct{}{} + sendTo = hasUpdate } else { - finished <- struct{}{} + sendTo = finished + } + + select { + case sendTo <- struct{}{}: + case <-closed: } }