]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go/internal/work: decrement concurrentProcesses when action finishes
authorMichael Matloob <matloob@golang.org>
Tue, 6 Jan 2026 22:18:48 +0000 (17:18 -0500)
committerMichael Matloob <matloob@google.com>
Wed, 7 Jan 2026 20:44:45 +0000 (12:44 -0800)
This fixes a bug where we only incremented concurrentProcesses but never
decremented it, causing us to run out of tokens and give all compiles
-c=1 after a point.

Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64_c2s16-perf_vs_parent,gotip-linux-amd64_c3h88-perf_vs_parent,gotip-linux-arm64_c4ah72-perf_vs_parent,gotip-linux-arm64_c4as16-perf_vs_parent
Change-Id: I41f4c1edb77004cbc1772d6d672045946a6a6964
Reviewed-on: https://go-review.googlesource.com/c/go/+/734260
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Michael Matloob <matloob@google.com>
TryBot-Bypass: Michael Matloob <matloob@google.com>

src/cmd/go/internal/work/exec.go
src/cmd/go/internal/work/gc.go

index 654e9e9374b2585f0b570f256113e97db21ea5cb..f2d1b1040b223b1f2a50435277032b1b797c44f3 100644 (file)
@@ -248,6 +248,11 @@ func (b *Builder) Do(ctx context.Context, root *Action) {
 
        wg.Wait()
 
+       if tokens != totalTokens || concurrentProcesses != 0 {
+               base.Fatalf("internal error: tokens not restored at end of build: tokens: %d, totalTokens: %d, concurrentProcesses: %d",
+                       tokens, totalTokens, concurrentProcesses)
+       }
+
        // Write action graph again, this time with timing information.
        writeActionGraph()
 }
index 9a5e6c924c3d409732b52916db4069d7177b1d04..fc74715f225bd3d03cb3b24e6d4bc5cbb6924fab 100644 (file)
@@ -227,6 +227,7 @@ func compilerConcurrency() (int, func()) {
        return c, func() {
                tokensMu.Lock()
                defer tokensMu.Unlock()
+               concurrentProcesses--
                tokens += c
        }
 }
@@ -235,6 +236,7 @@ var maxCompilerConcurrency = runtime.GOMAXPROCS(0) // max value we will use for
 
 var (
        tokensMu            sync.Mutex
+       totalTokens         int // total number of tokens: this is used for checking that we get them all back in the end
        tokens              int // number of available tokens
        concurrentProcesses int // number of currently running compiles
 )
@@ -246,6 +248,7 @@ func initCompilerConcurrencyPool() {
        // than what it was when we capped the concurrency to 4.
        oldConcurrencyCap := min(4, maxCompilerConcurrency)
        tokens = oldConcurrencyCap * cfg.BuildP
+       totalTokens = tokens
 }
 
 // trimpath returns the -trimpath argument to use