]> Cypherpunks repositories - gostls13.git/commit
cmd/go: keep objects alive while stopping cleanups
authorMichael Anthony Knyszek <mknyszek@google.com>
Wed, 12 Nov 2025 18:22:58 +0000 (18:22 +0000)
committerGopher Robot <gobot@golang.org>
Thu, 13 Nov 2025 00:14:30 +0000 (16:14 -0800)
commit0929d2197807c7b70ff0b1a17982259879e9c064
tree6fff6a9e0813e089aa790b2cd305306ee7348c21
parentf03d06ec1a69d77b4c43971cc474c3111a424c3a
cmd/go: keep objects alive while stopping cleanups

There are two places in cmd/go where cleanups are stopped before they
fire, and where the objects the cleanups are attached to may be dead
while we call Stop. This is essentially a race between Stop and the
cleanup being called. This can be fine, but these cleanups are used as
a way to check some invariants, so just panic if they're executed. As a
result, if they fire erroneously, they'll take down the whole process,
even if no invariant was actually violated.

The runtime.Cleanup.Stop documentation explains that users of Stop need
to hold the object alive across the call to Stop if they want to be sure
that Stop succeeds, so do that here by adding an explicit
runtime.KeepAlive call.

Kudos to Michael Pratt for finding the issue.

Fixes #74780.

Change-Id: I22e6f4642ac68f727ca3781f5d39a85015047925
Reviewed-on: https://go-review.googlesource.com/c/go/+/719961
Auto-Submit: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Carlos Amedee <carlos@golang.org>
src/cmd/go/internal/base/limit.go
src/cmd/go/internal/lockedfile/lockedfile.go