Scheduler: Catch exceptions thrown from AsyncTask->onCompletion()

This commit is contained in:
Dylan K. Taylor
2018-02-27 11:33:16 +00:00
parent e024f381c9
commit e0d5c79848
2 changed files with 13 additions and 3 deletions

View File

@ -159,8 +159,17 @@ class AsyncPool{
}
if($task->isGarbage() and !$task->isRunning() and !$task->isCrashed()){
if(!$task->hasCancelledRun()){
$task->onCompletion($this->server);
$this->server->getScheduler()->removeLocalComplex($task);
try{
$task->onCompletion($this->server);
if(!$this->server->getScheduler()->removeLocalComplex($task)){
$this->server->getLogger()->notice("AsyncTask " . get_class($task) . " stored local complex data but did not remove them after completion");
}
}catch(\Throwable $e){
$this->server->getLogger()->critical("Could not execute completion of asychronous task " . (new \ReflectionClass($task))->getShortName() . ": " . $e->getMessage());
$this->server->getLogger()->logException($e);
$this->server->getScheduler()->removeLocalComplex($task); //silent
}
}
$this->removeTask($task);