From 8006b58758b21d62eb46c4b438f5b5f013dfae8b Mon Sep 17 00:00:00 2001 From: JackDoan Date: Mon, 27 Jul 2026 15:40:14 -0500 Subject: [PATCH] util: unlock the OS thread when CPU pinning fails PinThreadToCPU left the goroutine locked to its OS thread even when sched_setaffinity failed. The lock only exists to make the affinity stick; without it the kernel migrates the thread anyway, so a failed pin kept a dedicated thread for zero benefit. Unwind on the error path. Co-Authored-By: Claude Fable 5 --- util/cpupin_linux.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/util/cpupin_linux.go b/util/cpupin_linux.go index 016e9bf8..d975b4af 100644 --- a/util/cpupin_linux.go +++ b/util/cpupin_linux.go @@ -19,7 +19,13 @@ func PinThreadToCPU(cpu int) error { var set unix.CPUSet set.Zero() set.Set(cpu) - return unix.SchedSetaffinity(0, &set) + if err := unix.SchedSetaffinity(0, &set); err != nil { + // Without the affinity the thread lock buys no TX-ring stability; + // don't leave the goroutine wedded to one OS thread for nothing. + runtime.UnlockOSThread() + return err + } + return nil } // AllowedCPUs returns the CPU IDs the calling process is currently allowed to