Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions src/Runtime/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@ public function start(int $port = 8080): void
$this->spawnWorkers($nWorkers);
} else {
$this->setupSignals([]);
$this->bootWorker();
try {
$this->bootWorker();
} catch (\Throwable $e) {
fwrite(STDERR, "[Worker " . getmypid() . "] Boot failed: {$e->getMessage()}\n");
exit(1);
}
$this->runEventLoop();
}
}
Expand All @@ -87,9 +92,17 @@ private function spawnWorkers(int $nWorkers): void

if ($pid === 0) {
// ── Child process ─────────────────────────────────────────────
// Reset signal handlers inherited from parent, then boot.
$this->setupSignals([]);
$this->bootWorker();
// Block signals until Rust heap is owned by this process
pcntl_sigprocmask(SIG_BLOCK, [SIGTERM, SIGINT]);
try {
$this->setupSignals([]);
$this->bootWorker();
} catch (\Throwable $e) {
fwrite(STDERR, "[Worker " . getmypid() . "] Boot failed: {$e->getMessage()}\n");
exit(1);
}
pcntl_sigprocmask(SIG_UNBLOCK, [SIGTERM, SIGINT]);

$this->runEventLoop();
exit(0);
}
Expand All @@ -99,7 +112,16 @@ private function spawnWorkers(int $nWorkers): void

// ── Parent process ────────────────────────────────────────────────────
$this->setupSignals($pids);
$this->bootWorker();
try {
$this->bootWorker();
} catch (\Throwable $e) {
fwrite(STDERR, "[Worker " . getmypid() . "] Boot failed: {$e->getMessage()}\n");
// Kill children before exiting
foreach ($pids as $pid) {
posix_kill($pid, SIGTERM);
}
exit(1);
}
$this->runEventLoop();

// Reap any remaining children after the parent's loop exits.
Expand Down
Loading