From 4abf4aecad100eb8768da16ac7314f0848cc653b Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sun, 28 Mar 2021 18:10:23 +0100 Subject: [PATCH] MainLogger: fixed potential deadlock during syncFlushBuffer() the notify() to flush the buffer might arrive in between the writeLogStream() and synchronized() calls in the thread body, resulting in a deadlock if the logger thread managed to call wait() before the main thread did. --- src/pocketmine/utils/MainLogger.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/pocketmine/utils/MainLogger.php b/src/pocketmine/utils/MainLogger.php index 4e34a1610..2846e0bfd 100644 --- a/src/pocketmine/utils/MainLogger.php +++ b/src/pocketmine/utils/MainLogger.php @@ -331,10 +331,11 @@ class MainLogger extends \AttachableThreadedLogger{ * @return void */ public function syncFlushBuffer(){ - $this->syncFlush = true; $this->synchronized(function() : void{ + $this->syncFlush = true; $this->notify(); //write immediately - + }); + $this->synchronized(function() : void{ while($this->syncFlush){ $this->wait(); //block until it's all been written to disk } @@ -371,7 +372,7 @@ class MainLogger extends \AttachableThreadedLogger{ while(!$this->shutdown){ $this->writeLogStream($logResource); $this->synchronized(function() : void{ - if(!$this->shutdown){ + if(!$this->shutdown && !$this->syncFlush){ $this->wait(); } });