From 8ce9aeee4e84ae43cbcdd0a56ceb6d3e1e19e967 Mon Sep 17 00:00:00 2001 From: petricadaipegsp <155911522+petricadaipegsp@users.noreply.github.com> Date: Wed, 20 Nov 2024 23:59:09 +0100 Subject: [PATCH] Disallow excessive GOMAXPROCS (#368) --- node/config/engine.go | 2 ++ node/main.go | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/node/config/engine.go b/node/config/engine.go index 3e15a6f..3078f31 100644 --- a/node/config/engine.go +++ b/node/config/engine.go @@ -34,4 +34,6 @@ type EngineConfig struct { // Values used only for testing – do not override these in production, your // node will get kicked out Difficulty uint32 `yaml:"difficulty"` + // Whether to allow GOMAXPROCS values above the number of physical cores. + AllowExcessiveGOMAXPROCS bool `yaml:"allowExcessiveGOMAXPROCS"` } diff --git a/node/main.go b/node/main.go index 0003832..c03fde0 100644 --- a/node/main.go +++ b/node/main.go @@ -394,6 +394,12 @@ func main() { nodeConfig.Engine.DataWorkerMemoryLimit = 1792 * 1024 * 1024 // 1.75GiB } if len(nodeConfig.Engine.DataWorkerMultiaddrs) == 0 { + maxProcs, numCPU := runtime.GOMAXPROCS(0), runtime.NumCPU() + if maxProcs > numCPU && !nodeConfig.Engine.AllowExcessiveGOMAXPROCS { + fmt.Println("GOMAXPROCS is set higher than the number of available CPUs.") + os.Exit(1) + } + nodeConfig.Engine.DataWorkerCount = qruntime.WorkerCount( nodeConfig.Engine.DataWorkerCount, true, )