]> Cypherpunks repositories - gostls13.git/commit
runtime: disable stack shrinking for all waiting-for-suspendG cases
authorMichael Anthony Knyszek <mknyszek@google.com>
Sat, 2 Aug 2025 03:26:43 +0000 (03:26 +0000)
committerGopher Robot <gobot@golang.org>
Fri, 15 Aug 2025 18:23:37 +0000 (11:23 -0700)
commitbd07fafb0a2f979b2be05d9a533182ca55428079
tree5008c7938aabb0c130d32244a056ae1b4b25bdc3
parenta651e2ea47586f1e29688202ff60c719bac6a05b
runtime: disable stack shrinking for all waiting-for-suspendG cases

Currently isShrinkStackSafe returns false if a goroutine is put into
_Gwaiting while it actually goes and executes on the system stack.
For a long time, we needed to be robust to the goroutine's stack
shrinking while we're executing on the system stack.

Unfortunately, this has become harder and harder to do over time. First,
the execution tracer might be invoked in these contexts and it may wish
to take a stack trace. We cannot take the stack trace if the garbage
collector might concurrently shrink the stack of the user goroutine we
want to trace. So, isShrinkStackSafe grew the condition that we wouldn't
try to shrink the stack in these cases if execution tracing was enabled.

Today, runtime.mutex may wish to take a stack trace for the mutex
profile, and it can happen in a very similar context. Taking the stack
trace is no longer safe.

This change takes the stance that we stop trying to make this work at
all, and instead guarantee that the stack won't move while we're in
these sensitive contexts.

Change-Id: Ibfad2d7a335ee97cecaa48001df0db9812deeab1
Reviewed-on: https://go-review.googlesource.com/c/go/+/692716
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
Auto-Submit: Michael Knyszek <mknyszek@google.com>
src/runtime/mgc.go
src/runtime/proc.go
src/runtime/stack.go