diff --git a/src/Factory.php b/src/Factory.php index d1e4cf1..fa78c6b 100644 --- a/src/Factory.php +++ b/src/Factory.php @@ -305,6 +305,16 @@ private function openSocketIo($filename, $flags = null) $deferred->reject(new \RuntimeException('No connection detected')); }); + $process->on('exit', function () use ($deferred, $server, $timeout) { + $this->loop->cancelTimer($timeout); + if (is_resource($server)) { + $this->loop->removeReadStream($server); + fclose($server); + } + + $deferred->reject(new \RuntimeException('Database process died while setting up connection')); + }); + $this->loop->addReadStream($server, function () use ($server, $timeout, $filename, $flags, $deferred, $process) { // accept once connection on server socket and stop server socket $this->loop->cancelTimer($timeout); diff --git a/tests/FunctionalFactoryTest.php b/tests/FunctionalFactoryTest.php index 0a3ee8a..96ca66a 100644 --- a/tests/FunctionalFactoryTest.php +++ b/tests/FunctionalFactoryTest.php @@ -61,7 +61,9 @@ public function testOpenReturnsPromiseWhichRejectsWithExceptionWhenPathIsInvalid echo 'Error: ' . $e->getMessage() . PHP_EOL; }); - $this->expectOutputString('Error: Unable to open database: unable to open database file' . PHP_EOL); + // Unable to open database: unable to open database file + // Unable to open database: bad parameter or other API misuse (only between PHP 7.4.0 and PHP 7.4.7 as per https://3v4l.org/9SjgK) + $this->expectOutputRegex('/^' . preg_quote('Error: Unable to open database: ', '/') . '.*$/'); Loop::run(); } @@ -82,7 +84,7 @@ public function testOpenReturnsPromiseWhichRejectsWithExceptionWhenExplicitPhpBi echo 'Error: ' . $e->getMessage() . PHP_EOL; }); - $this->expectOutputString('Error: No connection detected' . PHP_EOL); + $this->expectOutputString('Error: Database process died while setting up connection' . PHP_EOL); Loop::run(); } }