Skip to content

Commit a04a56e

Browse files
committed
Fix the Error:
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
1 parent 09bf1bf commit a04a56e

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

src/EventLoop/Internal/AbstractDriver.php

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ public function __construct()
7070
// PHP GC is broken on early 8.1 and 8.2 versions, see https://github.com/php/php-src/issues/10496
7171
/** @psalm-suppress RiskyTruthyFalsyComparison */
7272
if (!\getenv('REVOLT_DRIVER_SUPPRESS_ISSUE_10496')) {
73-
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');
73+
throw new \Error(
74+
'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'
75+
);
7476
}
7577
}
7678

@@ -119,7 +121,7 @@ public function run(): void
119121
$lambda();
120122

121123
throw new \Error(
122-
'Interrupt from event loop must throw an exception: ' . ClosureHelper::getDescription($lambda)
124+
'Interrupt from event loop must throw an exception: '.ClosureHelper::getDescription($lambda)
123125
);
124126
}
125127
}
@@ -330,7 +332,7 @@ public function getErrorHandler(): ?\Closure
330332
public function __debugInfo(): array
331333
{
332334
// @codeCoverageIgnoreStart
333-
return \array_map(fn (DriverCallback $callback) => [
335+
return \array_map(fn(DriverCallback $callback) => [
334336
'type' => $this->getType($callback->id),
335337
'enabled' => $callback->enabled,
336338
'referenced' => $callback->referenced,
@@ -400,9 +402,10 @@ final protected function error(\Closure $closure, \Throwable $exception): void
400402
{
401403
if ($this->errorHandler === null) {
402404
// Explicitly override the previous interrupt if it exists in this case, hiding the exception is worse
403-
$this->interrupt = static fn () => $exception instanceof UncaughtThrowable
405+
$this->interrupt = static fn() => $exception instanceof UncaughtThrowable
404406
? throw $exception
405407
: throw UncaughtThrowable::throwingCallback($closure, $exception);
408+
406409
return;
407410
}
408411

@@ -437,8 +440,12 @@ private function invokeMicrotasks(): void
437440
unset($callback, $args);
438441

439442
if ($this->interrupt) {
440-
/** @noinspection PhpUnhandledExceptionInspection */
441-
\Fiber::suspend($this->internalSuspensionMarker);
443+
try {
444+
/** @noinspection PhpUnhandledExceptionInspection */
445+
\Fiber::suspend($this->internalSuspensionMarker);
446+
} catch (\Throwable) {
447+
return;
448+
}
442449
}
443450
}
444451
}
@@ -622,7 +629,11 @@ private function createCallbackFiber(): void
622629
}
623630

624631
/** @noinspection PhpUnhandledExceptionInspection */
625-
\Fiber::suspend($this->internalSuspensionMarker);
632+
try {
633+
\Fiber::suspend($this->internalSuspensionMarker);
634+
} catch (\Throwable) {
635+
return;
636+
}
626637
} while (true);
627638
});
628639
}
@@ -633,7 +644,7 @@ private function createErrorCallback(): void
633644
try {
634645
$errorHandler($exception);
635646
} catch (\Throwable $exception) {
636-
$this->interrupt = static fn () => $exception instanceof UncaughtThrowable
647+
$this->interrupt = static fn() => $exception instanceof UncaughtThrowable
637648
? throw $exception
638649
: throw UncaughtThrowable::throwingErrorHandler($errorHandler, $exception);
639650
}
@@ -642,11 +653,11 @@ private function createErrorCallback(): void
642653

643654
final public function __serialize(): never
644655
{
645-
throw new \Error(__CLASS__ . ' does not support serialization');
656+
throw new \Error(__CLASS__.' does not support serialization');
646657
}
647658

648659
final public function __unserialize(array $data): never
649660
{
650-
throw new \Error(__CLASS__ . ' does not support deserialization');
661+
throw new \Error(__CLASS__.' does not support deserialization');
651662
}
652663
}

0 commit comments

Comments
 (0)