Skip to content

Commit 1c3d3f2

Browse files
committed
Fail fast without waiting for timeout if process dies while connecting
1 parent acf64a4 commit 1c3d3f2

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function testOpenReturnsPromiseWhichRejectsWithExceptionWhenExplicitPhpBi
8484
echo 'Error: ' . $e->getMessage() . PHP_EOL;
8585
});
8686

87-
$this->expectOutputString('Error: No connection detected' . PHP_EOL);
87+
$this->expectOutputString('Error: Database process died while setting up connection' . PHP_EOL);
8888
Loop::run();
8989
}
9090
}

0 commit comments

Comments
 (0)