mirror of
https://github.com/Vateron-Media/XC_VM.git
synced 2026-10-25 19:03:14 +01:00
A connection row records the PHP-FPM worker serving it (getmypid() in live.php, vod.php and timeshift.php), but the watchdog published as servers.php_pids the contents of bin/php/sockets/*.pid: the FPM master pids. In Redis mode MAIN's cron:users reaps every node's connections and, for a remote PHP-served connection older than the node's last heartbeat, checks the worker pid against that list. It never matched, so the connection was closed and the LB told to kill its worker: every VOD, timeshift and PHP-served live viewer on an LB was dropped about a minute after connecting. MySQL mode was unaffected (each node probes its own pids locally). - ProcessManager::phpFpmWorkerPIDs() lists the processes titled "php-fpm: pool xc_vm" (sorted, unique); findProcessPIDs() takes an optional procfs root so it can run against a fixture tree. - WatchdogCommand publishes that list instead of the pid files. - ServerRepository::getAll() drops php_pids from the rows it returns and caches, so the per-request servers cache does not carry every node's worker list. CacheCronJob's unset($rServers['php_pids']) meant to do that but hit a top-level key of an id-keyed map; it is removed. - UsersCronJob reads php_pids with its own SELECT `id`, `php_pids`. The `- 1` heartbeat margin is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TQHeypQpfAXTdCysmi7b6a
41 lines
1.3 KiB
PHP
41 lines
1.3 KiB
PHP
<?php
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
use XcVm\Cli\CronJobs\UsersCronJob;
|
|
|
|
/**
|
|
* UsersCronJob::loadPHPPIDs — in Redis mode MAIN's cron:users decides whether a
|
|
* remote node's PHP-served connection is still alive by looking its worker pid
|
|
* up in that node's servers.php_pids. ServerRepository::getAll() no longer
|
|
* carries the column (it is kept out of the per-request servers cache), so the
|
|
* reaper reads it with its own query. A node with no usable list maps to [],
|
|
* which the reaper treats as "cannot tell" and keeps the connection.
|
|
*/
|
|
final class UsersCronPhpPidsTest extends TestCase {
|
|
|
|
private $rDbBackup;
|
|
|
|
protected function setUp(): void {
|
|
$this->rDbBackup = $GLOBALS['db'] ?? null;
|
|
|
|
$rDb = new TestDb();
|
|
$rDb->exec('CREATE TABLE servers (id INTEGER PRIMARY KEY, php_pids TEXT);');
|
|
$rDb->exec('INSERT INTO servers (id, php_pids) VALUES (1, \'[11,12]\'), (2, NULL), (3, \'not json\'), (4, \'["13"]\');');
|
|
$GLOBALS['db'] = $rDb;
|
|
}
|
|
|
|
protected function tearDown(): void {
|
|
$GLOBALS['db'] = $this->rDbBackup;
|
|
}
|
|
|
|
public function testReadsEveryNodesWorkerPidsFromTheServersTable(): void {
|
|
$rMethod = new ReflectionMethod(UsersCronJob::class, 'loadPHPPIDs');
|
|
$rMethod->setAccessible(true);
|
|
|
|
$this->assertSame(
|
|
[1 => [11, 12], 2 => [], 3 => [], 4 => [13]],
|
|
$rMethod->invoke($rMethod->isStatic() ? null : new UsersCronJob())
|
|
);
|
|
}
|
|
}
|