From 66acb5cdd7972d6ebd2449177ebc50c0b8339316 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Fri, 31 Oct 2014 23:10:12 +0100 Subject: [PATCH] Possible fix for crashing server not stopping --- src/pocketmine/Server.php | 63 ++++++++++++-------- src/pocketmine/scheduler/ServerScheduler.php | 2 +- 2 files changed, 40 insertions(+), 25 deletions(-) diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index be7d3bcf2..73d763fd1 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -132,6 +132,8 @@ class Server{ /** @var bool */ private $isRunning = true; + private $hasStopped = false; + /** @var PluginManager */ private $pluginManager = null; @@ -1852,39 +1854,52 @@ class Server{ } public function forceShutdown(){ - $this->shutdown(); - if($this->rcon instanceof RCON){ - $this->rcon->stop(); + if($this->hasStopped){ + return; } - if($this->getProperty("settings.upnp-forwarding", false) === true){ - $this->logger->info("[UPnP] Removing port forward..."); - UPnP::RemovePortForward($this->getPort()); - } + try{ + $this->hasStopped = true; - $this->pluginManager->disablePlugins(); + $this->shutdown(); + if($this->rcon instanceof RCON){ + $this->rcon->stop(); + } - foreach($this->players as $player){ - $player->close(TextFormat::YELLOW . $player->getName() . " has left the game", $this->getProperty("settings.shutdown-message", "Server closed")); - } + if($this->getProperty("settings.upnp-forwarding", false) === true){ + $this->logger->info("[UPnP] Removing port forward..."); + UPnP::RemovePortForward($this->getPort()); + } - foreach($this->getLevels() as $level){ - $this->unloadLevel($level, true); - } + $this->pluginManager->disablePlugins(); - if($this->generationManager instanceof GenerationRequestManager){ - $this->generationManager->shutdown(); - } + foreach($this->players as $player){ + $player->close(TextFormat::YELLOW . $player->getName() . " has left the game", $this->getProperty("settings.shutdown-message", "Server closed")); + } - HandlerList::unregisterAll(); - $this->scheduler->cancelAllTasks(); - $this->scheduler->mainThreadHeartbeat(PHP_INT_MAX); + foreach($this->getLevels() as $level){ + $this->unloadLevel($level, true); + } - $this->properties->save(); + if($this->generationManager instanceof GenerationRequestManager){ + $this->generationManager->shutdown(); + } - $this->console->kill(); - foreach($this->interfaces as $interface){ - $interface->shutdown(); + HandlerList::unregisterAll(); + + $this->scheduler->cancelAllTasks(); + $this->scheduler->mainThreadHeartbeat(PHP_INT_MAX); + + $this->properties->save(); + + $this->console->kill(); + + foreach($this->interfaces as $interface){ + $interface->shutdown(); + } + }catch (\Exception $e){ + $this->logger->emergency("Crashed while crashing, killing process"); + @kill(getmypid()); } } diff --git a/src/pocketmine/scheduler/ServerScheduler.php b/src/pocketmine/scheduler/ServerScheduler.php index 835e647f8..a79589518 100644 --- a/src/pocketmine/scheduler/ServerScheduler.php +++ b/src/pocketmine/scheduler/ServerScheduler.php @@ -144,7 +144,7 @@ class ServerScheduler{ } $this->tasks = []; $this->asyncTaskStorage = []; - $this->asyncPool->shutdown(); + //$this->asyncPool->shutdown(); $this->asyncTasks = 0; $this->queue = new ReversePriorityQueue(); $this->asyncPool = new \Pool(self::$WORKERS, AsyncWorker::class);