浏览代码

prevent leaking goroutines

D1CED 4 年之前
父节点
当前提交
c8a74cb4a4
共有 1 个文件被更改,包括 12 次插入2 次删除
  1. 12 2
      pkg/vcs/vcs.go

+ 12 - 2
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:
 		}
 	}