Skip to content

Commit 9d16848

Browse files
authored
Merge pull request #46 from clue-labs/binary-fails
Fail fast without waiting for timeout if process dies while connecting
2 parents 234ac1a + 1c3d3f2 commit 9d16848

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/Factory.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,16 @@ private function openSocketIo($filename, $flags = null)
305305
$deferred->reject(new \RuntimeException('No connection detected'));
306306
});
307307

308+
$process->on('exit', function () use ($deferred, $server, $timeout) {
309+
$this->loop->cancelTimer($timeout);
310+
if (is_resource($server)) {
311+
$this->loop->removeReadStream($server);
312+
fclose($server);
313+
}
314+
315+
$deferred->reject(new \RuntimeException('Database process died while setting up connection'));
316+
});
317+
308318
$this->loop->addReadStream($server, function () use ($server, $timeout, $filename, $flags, $deferred, $process) {
309319
// accept once connection on server socket and stop server socket
310320
$this->loop->cancelTimer($timeout);

tests/FunctionalFactoryTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ public function testOpenReturnsPromiseWhichRejectsWithExceptionWhenPathIsInvalid
6161
echo 'Error: ' . $e->getMessage() . PHP_EOL;
6262
});
6363

64-
$this->expectOutputString('Error: Unable to open database: unable to open database file' . PHP_EOL);
64+
// Unable to open database: unable to open database file
65+
// 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)
66+
$this->expectOutputRegex('/^' . preg_quote('Error: Unable to open database: ', '/') . '.*$/');
6567
Loop::run();
6668
}
6769

@@ -82,7 +84,7 @@ public function testOpenReturnsPromiseWhichRejectsWithExceptionWhenExplicitPhpBi
8284
echo 'Error: ' . $e->getMessage() . PHP_EOL;
8385
});
8486

85-
$this->expectOutputString('Error: No connection detected' . PHP_EOL);
87+
$this->expectOutputString('Error: Database process died while setting up connection' . PHP_EOL);
8688
Loop::run();
8789
}
8890
}

0 commit comments

Comments
 (0)