]> Cypherpunks repositories - gostls13.git/commit
runtime: fix double wakeup in CPU profile buffer
authorNick Ripley <nick.ripley@datadoghq.com>
Fri, 21 Nov 2025 14:09:57 +0000 (14:09 +0000)
committerNick Ripley <nick.ripley@datadoghq.com>
Fri, 21 Nov 2025 21:24:46 +0000 (13:24 -0800)
commitb604148c4e8ad61640d12cde40379bc3c137d8a6
treed9174585a81691915eae8ef7adfec692c7c0542e
parent22f24f90b52958158a2de5fa68adf0faf7699e4e
runtime: fix double wakeup in CPU profile buffer

The profBuf.wakeupExtra method wakes up the profile reader if it's
sleeping, either when the buffer is closed or when there is a pending
overflow entry.  Unlike in profBuf.write, profBuf.wakeupExtra does not
clear the profReaderSleeping bit before doing the wakeup. As a result,
if there are two writes to a full buffer before the sleeping reader has
time to wake up, we'll see two consecutive calls to notewakeup, which is
a fatal error. This CL updates profBuf.wakeupExtra to clear the sleeping
bit before doing the wakeup.

This CL adds a unit test that demonstrates the problem. This is
theoretically possible to trigger for real programs as well, but it's
more difficult. The profBufWordCount is large enough that it takes
several CPU-seconds to fill up the buffer. So we'd need to run on a
system with lots of cores to have a chance of running into this failure,
and the reader would need to fully go to sleep before a large burst of
CPU activity.

Change-Id: I59b4fa86a12f6236890b82cd353a95706a6a6964
Reviewed-on: https://go-review.googlesource.com/c/go/+/722940
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Mark Freeman <markfreeman@google.com>
src/runtime/profbuf.go
src/runtime/profbuf_test.go