From f75ca312cc8916d88ee1afdf84ec976fa2633526 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sun, 21 Aug 2022 21:57:11 +0100 Subject: [PATCH] Worker: Unstack tasks in a synchronized block this prevents any tasks still left in the queue on shutdown getting pulled out by the worker when we're attempting to shut it down. This led to various race conditions, most notably weird cases where PopulationTask would inexplicably find its expected generator state had not been correctly set up. --- src/thread/Worker.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/thread/Worker.php b/src/thread/Worker.php index 1315202b1..572da3c67 100644 --- a/src/thread/Worker.php +++ b/src/thread/Worker.php @@ -56,7 +56,9 @@ abstract class Worker extends \Worker{ $this->isKilled = true; if(!$this->isShutdown()){ - while($this->unstack() !== null); + $this->synchronized(function() : void{ + while($this->unstack() !== null); + }); $this->notify(); $this->shutdown(); }