From 13ca2bac4d4470f2ac4530565c74fc719370dad9 Mon Sep 17 00:00:00 2001 From: Aaron Piotrowski Date: Wed, 23 Feb 2022 22:29:09 -0600 Subject: [PATCH] Fix fiber reference in error path --- src/EventLoop/Internal/DriverSuspension.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/EventLoop/Internal/DriverSuspension.php b/src/EventLoop/Internal/DriverSuspension.php index 462b612..b8d74ce 100644 --- a/src/EventLoop/Internal/DriverSuspension.php +++ b/src/EventLoop/Internal/DriverSuspension.php @@ -76,10 +76,11 @@ public function suspend(): mixed } $this->pending = true; - $this->suspendedFiber = $fiber; // Awaiting from within a fiber. if ($fiber) { + $this->suspendedFiber = $fiber; + try { return \Fiber::suspend(); } catch (\FiberError $exception) { @@ -105,12 +106,14 @@ public function suspend(): mixed if ($suspensions) { \gc_collect_cycles(); + /** @var self $suspension */ foreach ($suspensions as $suspension) { - if ($suspension->fiber === null) { + $fiber = $suspension->fiberRef?->get(); + if ($fiber === null) { continue; } - $reflectionFiber = new \ReflectionFiber($suspension->fiber); + $reflectionFiber = new \ReflectionFiber($fiber); $info .= "\n\n" . $this->formatStacktrace($reflectionFiber->getTrace(\DEBUG_BACKTRACE_IGNORE_ARGS)); } }