Fixed uncaught exceptions during Task->onCancel() causing all kinds of nasty behaviour

including crashing the server on shutdown, preventing self-cancellation, and causing memory leaks
This commit is contained in:
Dylan K. Taylor 2017-09-02 19:28:51 +01:00
parent 2f614c5dc2
commit 1d338bfdf9

View File

@ -25,6 +25,7 @@ namespace pocketmine\scheduler;
use pocketmine\event\Timings;
use pocketmine\event\TimingsHandler;
use pocketmine\utils\MainLogger;
class TaskHandler{
@ -136,10 +137,15 @@ class TaskHandler{
* Changes to this function won't be recorded on the version.
*/
public function cancel(){
if(!$this->isCancelled()){
$this->task->onCancel();
try{
if(!$this->isCancelled()){
$this->task->onCancel();
}
}catch(\Throwable $e){
MainLogger::getLogger()->logException($e);
}finally{
$this->remove();
}
$this->remove();
}
public function remove(){