From 64699542031b994ec4fdb6de887a94b69a372f9b Mon Sep 17 00:00:00 2001 From: Michael Pratt Date: Mon, 6 Oct 2025 16:38:29 -0400 Subject: [PATCH] runtime: assert p.destroy runs with GC not running This is already guaranteed by stopTheWorldGC prior to procresize. Thus the cleanup code here is dead, which is a bit confusing. Replace it with a throw for clarity. Change-Id: I6a6a636c8ca1487b720c4fab41b2b86c13d1d9e0 Reviewed-on: https://go-review.googlesource.com/c/go/+/709655 LUCI-TryBot-Result: Go LUCI Reviewed-by: Michael Knyszek --- src/runtime/proc.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/runtime/proc.go b/src/runtime/proc.go index e568670529..d36895b046 100644 --- a/src/runtime/proc.go +++ b/src/runtime/proc.go @@ -5818,11 +5818,13 @@ func (pp *p) destroy() { // Move all timers to the local P. getg().m.p.ptr().timers.take(&pp.timers) - // Flush p's write barrier buffer. - if gcphase != _GCoff { - wbBufFlush1(pp) - pp.gcw.dispose() + // No need to flush p's write barrier buffer or span queue, as Ps + // cannot be destroyed during the mark phase. + if phase := gcphase; phase != _GCoff { + println("runtime: p id", pp.id, "destroyed during GC phase", phase) + throw("P destroyed while GC is running") } + clear(pp.sudogbuf[:]) pp.sudogcache = pp.sudogbuf[:0] pp.pinnerCache = nil -- 2.52.0