From 6bdad167c3b3d3154310822b9d2d7bc5e3378666 Mon Sep 17 00:00:00 2001 From: ALIF AKBAR Date: Thu, 6 Aug 2026 12:59:55 +0700 Subject: [PATCH] fix(core): dynamically set msg_receive buffer size to prevent CPU spin Resolves an issue where a hardcoded 8192-byte `msg_receive()` buffer causes a CPU-spin poison message when `kernel.msgmax` is raised above the default. --- Core/src/Batch/BatchJob.php | 5 ++++- Core/tests/Unit/Batch/SysvProcessorTest.php | 6 +++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Core/src/Batch/BatchJob.php b/Core/src/Batch/BatchJob.php index 05b5535f3e88..6da598290e47 100644 --- a/Core/src/Batch/BatchJob.php +++ b/Core/src/Batch/BatchJob.php @@ -106,6 +106,9 @@ public function run() $q = msg_get_queue($sysvKey); $items = []; $lastInvoked = microtime(true); + $maxSize = is_array($stat = @msg_stat_queue($q)) && isset($stat['msg_qbytes']) + ? $stat['msg_qbytes'] + : 8192; if (!is_null($this->bootstrapFile)) { require_once($this->bootstrapFile); @@ -118,7 +121,7 @@ public function run() $q, 0, $type, - 8192, + $maxSize, $message, true, 0, // blocking mode diff --git a/Core/tests/Unit/Batch/SysvProcessorTest.php b/Core/tests/Unit/Batch/SysvProcessorTest.php index bcaa13f920e7..d70a751e673a 100644 --- a/Core/tests/Unit/Batch/SysvProcessorTest.php +++ b/Core/tests/Unit/Batch/SysvProcessorTest.php @@ -193,11 +193,15 @@ private function send($message, $type = null) private function receive(&$type, &$message, &$errorcode, $unserialize = false) { + $maxSize = is_array($stat = @msg_stat_queue($this->queue)) && isset($stat['msg_qbytes']) + ? $stat['msg_qbytes'] + : 8192; + return @msg_receive( $this->queue, 0, $type, - 8192, + $maxSize, $message, $unserialize, MSG_IPC_NOWAIT,