From 09db5b8e91669f0b16d7034c0b3effc0d2bc0c60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Ha=C5=82as?= Date: Thu, 30 Apr 2026 21:36:34 +0200 Subject: [PATCH 1/2] fix(Runner): check mkdir() return value to prevent silent failures Closes #151 --- src/Runner.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Runner.php b/src/Runner.php index a76a012..3247c64 100644 --- a/src/Runner.php +++ b/src/Runner.php @@ -107,8 +107,8 @@ public function run(): int assert(is_int($stopTimeout)); assert(is_int($maxPackageSize)); - if (!is_dir($varRunDir = dirname($pidFile))) { - mkdir(directory: $varRunDir, recursive: true); + if (!is_dir($varRunDir = dirname($pidFile)) && !mkdir(directory: $varRunDir, recursive: true) && !is_dir($varRunDir)) { + throw new \RuntimeException(sprintf('Unable to create directory "%s".', $varRunDir)); } TcpConnection::$defaultMaxPackageSize = $maxPackageSize; From 90c8d19cbc30e108711adf83293ecb682e7c52d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Ha=C5=82as?= Date: Thu, 30 Apr 2026 21:43:31 +0200 Subject: [PATCH 2/2] refactor(Runner): address PR review feedback - Use \sprintf() for consistency with rest of file - Add structural test for mkdir() failure path - Add CHANGELOG entry under [Unreleased] --- CHANGELOG.md | 6 ++++++ src/Runner.php | 2 +- tests/RunnerTest.php | 6 ++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a686b8e..1ebfdf5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -56,6 +56,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- Fixed `Runner::run()` — `mkdir()` return value now checked to prevent silent failures ([#151](https://github.com/crazy-goat/workerman-bundle/issues/151)) + - Throws `\RuntimeException` with clear message when directory creation fails + - Double `is_dir()` check handles race condition between check and `mkdir()` call + ## [0.14.0] - 2026-04-14 ### Deprecated diff --git a/src/Runner.php b/src/Runner.php index 3247c64..5a812a4 100644 --- a/src/Runner.php +++ b/src/Runner.php @@ -108,7 +108,7 @@ public function run(): int assert(is_int($maxPackageSize)); if (!is_dir($varRunDir = dirname($pidFile)) && !mkdir(directory: $varRunDir, recursive: true) && !is_dir($varRunDir)) { - throw new \RuntimeException(sprintf('Unable to create directory "%s".', $varRunDir)); + throw new \RuntimeException(\sprintf('Unable to create directory "%s".', $varRunDir)); } TcpConnection::$defaultMaxPackageSize = $maxPackageSize; diff --git a/tests/RunnerTest.php b/tests/RunnerTest.php index 3f0608d..90bfb2f 100644 --- a/tests/RunnerTest.php +++ b/tests/RunnerTest.php @@ -74,6 +74,12 @@ public function testRunnerUsesCorrectForkErrorHandling(): void $content, 'Must have CACHE_WARMUP_TIMEOUT constant', ); + + $this->assertStringContainsString( + 'Unable to create directory', + $content, + 'Must throw when mkdir() fails to create var/run directory', + ); } /**