From 7765c654093f4b6f08b073d478bb42a52b7f2bb0 Mon Sep 17 00:00:00 2001 From: Niklas Keller Date: Sun, 23 Jul 2023 20:40:33 +0200 Subject: [PATCH] Add runtime check for serious GC bugs in PHP The check is added to the constructor instead of EventLoop::getDriver() or similar to ensure it only fails if Revolt is used, but without affecting hot code paths. --- src/EventLoop/Internal/AbstractDriver.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/EventLoop/Internal/AbstractDriver.php b/src/EventLoop/Internal/AbstractDriver.php index d04483c..3565d20 100644 --- a/src/EventLoop/Internal/AbstractDriver.php +++ b/src/EventLoop/Internal/AbstractDriver.php @@ -43,7 +43,7 @@ abstract class AbstractDriver implements Driver /** @var null|\Closure(\Throwable):void */ private ?\Closure $errorHandler = null; - /** @var null|\Closure():mixed */ + /** @var null|\Closure():mixed */ private ?\Closure $interrupt = null; private readonly \Closure $interruptCallback; @@ -65,6 +65,13 @@ abstract class AbstractDriver implements Driver public function __construct() { + if (\PHP_VERSION_ID < 80117 || \PHP_VERSION_ID >= 80200 && \PHP_VERSION_ID < 80204) { + // PHP GC is broken on early 8.1 and 8.2 versions, see https://github.com/php/php-src/issues/10496 + 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'); + } + } + $this->suspensions = new \WeakMap(); $this->internalSuspensionMarker = new \stdClass();