Skip to content

Commit 2556eb7

Browse files
runtime: ignore SIGPROF if profiling disable for thread
This avoids a deadlock on prof.signalLock between setcpuprofilerate and cpuprof.add if a SIGPROF is delivered to the thread between the call to setThreadCPUProfiler and acquiring prof.signalLock. Fixes #41014 Change-Id: Ie825e8594f93a19fb1a6320ed640f4e631553596 Reviewed-on: https://go-review.googlesource.com/c/go/+/253758 Run-TryBot: Ian Lance Taylor <[email protected]> Reviewed-by: Bryan C. Mills <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 34835df commit 2556eb7

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/runtime/proc.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3928,6 +3928,13 @@ func sigprof(pc, sp, lr uintptr, gp *g, mp *m) {
39283928
return
39293929
}
39303930

3931+
// If mp.profilehz is 0, then profiling is not enabled for this thread.
3932+
// We must check this to avoid a deadlock between setcpuprofilerate
3933+
// and the call to cpuprof.add, below.
3934+
if mp != nil && mp.profilehz == 0 {
3935+
return
3936+
}
3937+
39313938
// On mips{,le}, 64bit atomics are emulated with spinlocks, in
39323939
// runtime/internal/atomic. If SIGPROF arrives while the program is inside
39333940
// the critical section, it creates a deadlock (when writing the sample).

0 commit comments

Comments
 (0)