Fixed race condition in MainLogger shutdown

this resulted in a deadlock in https://github.com/pmmp/PocketMine-MP/runs/1831812620?check_suite_focus=true because the notify() arrived while writeLogStream() was executing.
This ensures that either:
- the notification will occur before the sleep, and therefore no sleeping will occur (this->shutdown = true before the wait)
- the notification will arrive during the sleep.
This commit is contained in:
Dylan K. Taylor 2021-02-04 16:40:10 +00:00
parent 8ef1e54e20
commit 7e3e63f342
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -278,8 +278,10 @@ class MainLogger extends \AttachableThreadedLogger{
* @return void
*/
public function shutdown(){
$this->shutdown = true;
$this->notify();
$this->synchronized(function() : void{
$this->shutdown = true;
$this->notify();
});
}
/**
@ -368,7 +370,9 @@ class MainLogger extends \AttachableThreadedLogger{
while(!$this->shutdown){
$this->writeLogStream($logResource);
$this->synchronized(function() : void{
$this->wait();
if(!$this->shutdown){
$this->wait();
}
});
}