Skip to content

Commit

Permalink
Fix the Error:
Browse files Browse the repository at this point in the history
Fatal error: Uncaught FiberError: Cannot suspend in a force-closed fiber in /srv/app/vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php:441 Stack trace: #0 /srv/app/vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(441): Fiber::suspend(Object(stdClass)) revoltphp#1 /srv/app/vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(567): Revolt\EventLoop\Internal\AbstractDriver->invokeMicrotasks() revoltphp#2 [internal function]: Revolt\EventLoop\Internal\AbstractDriver->Revolt\EventLoop\Internal\{closure}() revoltphp#3 {main} thrown in /srv/app/vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php on line 441
  • Loading branch information
digitaltim-de committed Jan 26, 2025
1 parent 09bf1bf commit a04a56e
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions src/EventLoop/Internal/AbstractDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
);
}
}

Expand Down Expand Up @@ -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)
);
}
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
}
}
}
Expand Down Expand Up @@ -622,7 +629,11 @@ private function createCallbackFiber(): void
}

/** @noinspection PhpUnhandledExceptionInspection */
\Fiber::suspend($this->internalSuspensionMarker);
try {
\Fiber::suspend($this->internalSuspensionMarker);
} catch (\Throwable) {
return;
}
} while (true);
});
}
Expand All @@ -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);
}
Expand All @@ -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');
}
}

0 comments on commit a04a56e

Please sign in to comment.