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 a76a012..5a812a4 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; 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', + ); } /**