From 4baaa7d93fd544b8fc82faa08372c8f745c366da Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Tue, 2 Jun 2026 22:03:10 +0100 Subject: [PATCH] Fix coroutine starvation: scale pools to coroutine count, serialize SMTP workers Two CI failure causes: - Connection pools are sized for HTTP-server worker counts and came out at 1 per worker process; 8 consume coroutines exhausted them (Pool 'cache_redis_main' is empty). Floor the pool size at _APP_WORKER_MAX_COROUTINES. - The mails and messaging workers disable the Swoole TCP hook at runtime to work around the TLS handshake crash (swoole-src#4909, #7914). The flag is process-global, so after the first job every blocking Redis pop freezes the coroutine scheduler and deliveries arrive minutes late. Both workers stay at 1 coroutine, matching pre-coroutine behavior. Co-Authored-By: Claude Opus 4.8 (1M context) --- app/init/registers.php | 4 ++++ docker-compose.yml | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/init/registers.php b/app/init/registers.php index 881aadd249..2f5f39ceb0 100644 --- a/app/init/registers.php +++ b/app/init/registers.php @@ -254,6 +254,10 @@ $register->set('pools', function () { $workerCount = intval(System::getEnv('_APP_CPU_NUM', swoole_cpu_num())) * intval(System::getEnv('_APP_WORKER_PER_CORE', 6)); $poolSize = max(1, (int)($instanceConnections / $workerCount)); + // Queue workers consume jobs concurrently with coroutines; each in-flight + // job may hold a connection, so pools must cover the coroutine count. + $poolSize = max($poolSize, (int) System::getEnv('_APP_WORKER_MAX_COROUTINES', 1)); + foreach ($connections as $key => $connection) { $type = $connection['type']; $multiple = $connection['multiple']; diff --git a/docker-compose.yml b/docker-compose.yml index a065408197..90bea1dc5d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -800,7 +800,7 @@ services: environment: - _APP_ENV - _APP_WORKERS_NUM=1 - - _APP_WORKER_MAX_COROUTINES=8 + - _APP_WORKER_MAX_COROUTINES=1 - _APP_WORKER_PER_CORE - _APP_POOL_ADAPTER - _APP_OPENSSL_KEY_V1 @@ -843,7 +843,7 @@ services: environment: - _APP_ENV - _APP_WORKERS_NUM=1 - - _APP_WORKER_MAX_COROUTINES=8 + - _APP_WORKER_MAX_COROUTINES=1 - _APP_WORKER_PER_CORE - _APP_POOL_ADAPTER - _APP_OPENSSL_KEY_V1