diff --git a/src/EventLoop/Internal/AbstractDriver.php b/src/EventLoop/Internal/AbstractDriver.php index 94de316..f0ddaa1 100644 --- a/src/EventLoop/Internal/AbstractDriver.php +++ b/src/EventLoop/Internal/AbstractDriver.php @@ -70,7 +70,9 @@ public function __construct() // PHP GC is broken on early 8.1 and 8.2 versions, see https://github.com/php/php-src/issues/10496 /** @psalm-suppress RiskyTruthyFalsyComparison */ if (!\getenv('REVOLT_DRIVER_SUPPRESS_ISSUE_10496')) { - throw new \Error('Your version of PHP is affected by serious garbage collector bugs related to fibers. Please upgrade to a newer version of PHP, i.e. >= 8.1.17 or => 8.2.4'); + throw new \Error( + 'Your version of PHP is affected by serious garbage collector bugs related to fibers. Please upgrade to a newer version of PHP, i.e. >= 8.1.17 or => 8.2.4' + ); } } @@ -119,7 +121,7 @@ public function run(): void $lambda(); throw new \Error( - 'Interrupt from event loop must throw an exception: ' . ClosureHelper::getDescription($lambda) + 'Interrupt from event loop must throw an exception: '.ClosureHelper::getDescription($lambda) ); } } @@ -330,7 +332,7 @@ public function getErrorHandler(): ?\Closure public function __debugInfo(): array { // @codeCoverageIgnoreStart - return \array_map(fn (DriverCallback $callback) => [ + return \array_map(fn(DriverCallback $callback) => [ 'type' => $this->getType($callback->id), 'enabled' => $callback->enabled, 'referenced' => $callback->referenced, @@ -400,9 +402,10 @@ final protected function error(\Closure $closure, \Throwable $exception): void { if ($this->errorHandler === null) { // Explicitly override the previous interrupt if it exists in this case, hiding the exception is worse - $this->interrupt = static fn () => $exception instanceof UncaughtThrowable + $this->interrupt = static fn() => $exception instanceof UncaughtThrowable ? throw $exception : throw UncaughtThrowable::throwingCallback($closure, $exception); + return; } @@ -437,8 +440,12 @@ private function invokeMicrotasks(): void unset($callback, $args); if ($this->interrupt) { - /** @noinspection PhpUnhandledExceptionInspection */ - \Fiber::suspend($this->internalSuspensionMarker); + try { + /** @noinspection PhpUnhandledExceptionInspection */ + \Fiber::suspend($this->internalSuspensionMarker); + } catch (\Throwable) { + return; + } } } } @@ -622,7 +629,11 @@ private function createCallbackFiber(): void } /** @noinspection PhpUnhandledExceptionInspection */ - \Fiber::suspend($this->internalSuspensionMarker); + try { + \Fiber::suspend($this->internalSuspensionMarker); + } catch (\Throwable) { + return; + } } while (true); }); } @@ -633,7 +644,7 @@ private function createErrorCallback(): void try { $errorHandler($exception); } catch (\Throwable $exception) { - $this->interrupt = static fn () => $exception instanceof UncaughtThrowable + $this->interrupt = static fn() => $exception instanceof UncaughtThrowable ? throw $exception : throw UncaughtThrowable::throwingErrorHandler($errorHandler, $exception); } @@ -642,11 +653,11 @@ private function createErrorCallback(): void final public function __serialize(): never { - throw new \Error(__CLASS__ . ' does not support serialization'); + throw new \Error(__CLASS__.' does not support serialization'); } final public function __unserialize(array $data): never { - throw new \Error(__CLASS__ . ' does not support deserialization'); + throw new \Error(__CLASS__.' does not support deserialization'); } }