From 94fb5d95b92604840dabb719f04327efa559cf94 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 17 May 2025 19:09:54 +0100 Subject: [PATCH] CommonThreadPartsTrait: fixed thread crashes sometimes missing cause info closes #6669 this happens because isTerminated returns true before the thread's shutdown handler runs, so we join with the thread to make sure that shutdown handlers are done before returning. ... hopefully we don't get servers randomly deadlocking in shutdown handlers ??? --- src/thread/CommonThreadPartsTrait.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/thread/CommonThreadPartsTrait.php b/src/thread/CommonThreadPartsTrait.php index e1c9d7c6b..de606a7b2 100644 --- a/src/thread/CommonThreadPartsTrait.php +++ b/src/thread/CommonThreadPartsTrait.php @@ -94,7 +94,17 @@ trait CommonThreadPartsTrait{ } } - public function getCrashInfo() : ?ThreadCrashInfo{ return $this->crashInfo; } + public function getCrashInfo() : ?ThreadCrashInfo{ + //TODO: Joining a crashed worker might be a bit sus, but we need to make sure the thread's shutdown + //handler has run before we try to collect the crash info. As of 6.1.1, pmmpthread sets isTerminated=true + //*before* the shutdown handler is invoked, so we might land here before the crash info has been set. + //In the future this should probably be fixed by running the shutdown handlers before setting isTerminated, + //but this workaround should be good enough for now. + if($this->isTerminated() && !$this->isJoined()){ + $this->join(); + } + return $this->crashInfo; + } public function start(int $options = NativeThread::INHERIT_NONE) : bool{ ThreadManager::getInstance()->add($this);