mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-20 16:00:20 +00:00
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.
This commit is contained in:
parent
b29f83ee99
commit
4abf4aecad
@ -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();
|
||||
}
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user