From f63095ae567d045a76e799ac01cfe6fc7932f092 Mon Sep 17 00:00:00 2001
From: Bensong Liu <bensl@microsoft.com>
Date: Mon, 26 Apr 2021 14:59:02 +0800
Subject: [PATCH] goroutine count limit

---
 main.go           | 2 +-
 packageManager.go | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/main.go b/main.go
index ed1d0d3..946e3bd 100644
--- a/main.go
+++ b/main.go
@@ -10,7 +10,7 @@ import (
 // Some options here. Would be improved in beta release.
 const DEDUCT_PKGNAME_FROM_VARNAME = true
 const USE_PROJECT_NETVER_INSTEAD_OF_HINTPATH_NETVER = false
-const OPENXT_VERSION = "1.1b"
+const OPENXT_VERSION = "1.1b-2"
 
 func print_help_and_exit() {
 	println("Usage: openxt <subcommand> [options...]")
diff --git a/packageManager.go b/packageManager.go
index 6fcdbb7..de69231 100644
--- a/packageManager.go
+++ b/packageManager.go
@@ -28,16 +28,16 @@ func ScanForDependencies(scanPath string) (allDeps []dependencyItem) {
 // Download `allDeps` to localRepoPath, with nuget.config from nugetConfigPath.
 // However, nugetConfigPath is not supported now. We use default nuget.config now. (Usually in ~/.nuget/)
 func SyncPackages(nugetConfigPath, localRepoPath string, allDeps []dependencyItem) {
-	log.Println("WARNING: We do not support custom nugetConfigPath yet. Please make sure your default nuget.config works. (usually ~/.nuget/NuGet/NuGet.Config)")
-
 	// Prepare nuget local repo
 	depsToSync := depsDeduplicate(allDeps)
 
 	var wg sync.WaitGroup
+	concurrencyLimitChan := make(chan int, 64)
 	for index_, dep_ := range depsToSync {
 		wg.Add(1)
+		concurrencyLimitChan <- 1 // will block if there's already 64 goroutine running
 		go func(index int, dep dependencyItem) {
-			defer wg.Done()
+			defer func() {<-concurrencyLimitChan ; wg.Done()}()
 			log.Printf("[%v/%v] Begin downloading: %v:%v as var %v", index, len(depsToSync), dep.pkgName, dep.targetNetVer, dep.envName)
 			log.Println("nuget-download-package", dep.pkgName, dep.targetNetVer, localRepoPath, nugetConfigPath)
 
-- 
GitLab