Skip to content
This repository has been archived by the owner on Jan 13, 2022. It is now read-only.

Commit

Permalink
Don't sent SIGTERM to hhvm
Browse files Browse the repository at this point in the history
  • Loading branch information
fredemmott committed May 19, 2015
1 parent 5f708c5 commit 41dbf5d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
25 changes: 20 additions & 5 deletions base/HHVMDaemon.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,15 +216,30 @@ public function start(): void {

<<__Override>>
public function stop(): void {
if (!$this->isRunning()) {
return;
}

try {
$health = $this->adminRequest('/check-health');
if ($health && json_decode($health)) {
$this->adminRequest('/stop');
invariant(!$this->isRunning(), 'Failed to stop HHVM');
if (!($health && json_decode($health))) {
parent::stop();
return;
}
} catch (Exception $e) { }
$time = microtime(true);
$this->adminRequest('/stop');
$this->waitForStop(10, 0.1);
} catch (Exception $e) {
}

parent::stop();
$pid = $this->getPid();
if ($this->isRunning() && $pid !== null) {
posix_kill($pid, SIGKILL);
}
invariant(
$this->waitForStop(1, 0.1),
"HHVM is unstoppable!",
);
}

public function writeStats(): void {
Expand Down
16 changes: 12 additions & 4 deletions base/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,22 @@ public function stop(): void {
if ($pid !== null) {
posix_kill($pid, SIGTERM);
}
for ($i = 0; $this->isRunning() && $i < 8; ++$i) {
self::sleepSeconds(0.25);
}
if ($this->isRunning()) {
if (!$this->waitForStop(2, 0.25)) {
posix_kill($pid, SIGKILL);
}
}

protected function waitForStop(num $max_time, num $interval): bool {
for (
$elapsed = 0;
$elapsed < $max_time && $this->isRunning();
$elapsed += $interval
) {
self::sleepSeconds((float) $interval);
}
return !$this->isRunning();
}

protected function getPidFilePath(): ?string {
return null;
}
Expand Down

0 comments on commit 41dbf5d

Please sign in to comment.