One failure stops one program
nvs serve runs each request on its own. A request that crashes, runs out of memory or loops
forever stops only that request. The server and every other request keep running.
You can see the same thing in one program. This program starts a child program that fails:
<?nvs// This program starts a child program that fails, and keeps running.var $failed = await spawn script 'one-failure-child.nvs' with(arguments: true, output: 'capture');
// The error of the child is part of its result. The parent does not stop.echo 'ok=', $failed->ok ? 'true' : 'false', "\n";echo 'error=', $failed->error?->class ?? 'none', "\n";echo "parent still running\n";ok=falseerror=RecursionErrorparent still runningThis is the child program, one-failure-child.nvs:
<?nvs// This is the file one-failure-child.nvs. When the parent starts it with `arguments: true`,// a method calls itself until the call stack is too deep.class Down{ public static function forever(int $n): int { return Down::forever($n + 1) + 1; }}
echo "child started\n";if (Core\Script::arguments() == true) { echo Down::forever(0), "\n";}child startedThe child calls itself until the call stack is too deep, and it stops with a RecursionError. The
parent gets the error as part of the result, and it keeps running.
A child also has its own copy of every static property. One request cannot change a value that another request reads.
Read more in Syntax: isolates and Syntax: limits.
