From 79bc1d6c85d18686767746464d14d8527cca5e83 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Tue, 4 Nov 2014 17:15:20 +0100 Subject: [PATCH] Fixed server not stopping after a special crash --- src/pocketmine/CrashDump.php | 2 +- src/pocketmine/Server.php | 41 +++++++++++-------- .../level/format/mcregion/McRegion.php | 3 +- src/pocketmine/utils/MainLogger.php | 2 +- 4 files changed, 28 insertions(+), 20 deletions(-) diff --git a/src/pocketmine/CrashDump.php b/src/pocketmine/CrashDump.php index 8f6218f99..cbd419397 100644 --- a/src/pocketmine/CrashDump.php +++ b/src/pocketmine/CrashDump.php @@ -137,7 +137,7 @@ class CrashDump{ $error = $lastExceptionError; }else{ $error = (array) error_get_last(); - $error["trace"] = getTrace(4); + $error["trace"] = @getTrace(4); $errorConversion = [ E_ERROR => "E_ERROR", E_WARNING => "E_WARNING", diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index e947ed923..df18fbae7 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -1589,7 +1589,6 @@ class Server{ set_exception_handler([$this, "exceptionHandler"]); register_shutdown_function([$this, "crashDump"]); - register_shutdown_function([$this, "forceShutdown"]); $this->pluginManager->loadPlugins($this->pluginPath); @@ -1905,6 +1904,7 @@ class Server{ $this->logger->emergency("Crashed while crashing, killing process"); @kill(getmypid()); } + } /** @@ -2002,7 +2002,7 @@ class Server{ "fullFile" => $e->getFile(), "file" => $errfile, "line" => $errline, - "trace" => getTrace($trace === null ? 3 : 0, $trace) + "trace" => @getTrace($trace === null ? 3 : 0, $trace) ]; global $lastExceptionError, $lastError; @@ -2014,7 +2014,11 @@ class Server{ if($this->isRunning === false){ return; } - ini_set("memory_limit", "-1"); //Fix error dump not dumped on memory problems + $this->isRunning = false; + $this->hasStopped = false; + + ini_set("error_reporting", 0); + ini_set("memory_limit", -1); //Fix error dump not dumped on memory problems $this->logger->emergency("An unrecoverable error has occurred and the server has crashed. Creating a crash dump"); $dump = new CrashDump($this); @@ -2022,30 +2026,33 @@ class Server{ if($this->getProperty("auto-report.enabled", true) !== false){ + $report = true; $plugin = $dump->getData()["plugin"]; if(is_string($plugin)){ $p = $this->pluginManager->getPlugin($plugin); if($p instanceof Plugin and !($p->getPluginLoader() instanceof PharPluginLoader)){ - return; + $report = false; } }elseif(\Phar::running(true) == ""){ - return; + $report = false; } if($dump->getData()["error"]["type"] === "E_PARSE" or $dump->getData()["error"]["type"] === "E_COMPILE_ERROR"){ - return; + $report = false; } - $reply = Utils::postURL("http://" . $this->getProperty("auto-report.host", "crash.pocketmine.net") . "/submit/api", [ - "report" => "yes", - "name" => $this->getName() . " " . $this->getPocketMineVersion(), - "email" => "crash@pocketmine.net", - "reportPaste" => base64_encode($dump->getEncodedData()) - ]); + if($report){ + $reply = Utils::postURL("http://" . $this->getProperty("auto-report.host", "crash.pocketmine.net") . "/submit/api", [ + "report" => "yes", + "name" => $this->getName() . " " . $this->getPocketMineVersion(), + "email" => "crash@pocketmine.net", + "reportPaste" => base64_encode($dump->getEncodedData()) + ]); - if(($data = json_decode($reply)) !== false and isset($data->crashId)){ - $reportId = $data->crashId; - $reportUrl = $data->crashUrl; - $this->logger->emergency("The crash dump has been automatically submitted to the Crash Archive. You can view it on $reportUrl or use the ID #$reportId."); + if(($data = json_decode($reply)) !== false and isset($data->crashId)){ + $reportId = $data->crashId; + $reportUrl = $data->crashUrl; + $this->logger->emergency("The crash dump has been automatically submitted to the Crash Archive. You can view it on $reportUrl or use the ID #$reportId."); + } } } @@ -2053,7 +2060,7 @@ class Server{ //$dump .= "Memory Usage Tracking: \r\n" . chunk_split(base64_encode(gzdeflate(implode(";", $this->memoryStats), 9))) . "\r\n"; $this->forceShutdown(); - kill(getmypid()); + @kill(getmypid()); exit(1); } diff --git a/src/pocketmine/level/format/mcregion/McRegion.php b/src/pocketmine/level/format/mcregion/McRegion.php index 236000341..a89aeb3c1 100644 --- a/src/pocketmine/level/format/mcregion/McRegion.php +++ b/src/pocketmine/level/format/mcregion/McRegion.php @@ -193,9 +193,10 @@ class McRegion extends BaseLevelProvider{ $chunk = $this->getChunk($x, $z, false); if($chunk instanceof FullChunk and $chunk->unload(false, $safe)){ unset($this->chunks[Level::chunkHash($x, $z)]); + return true; } - return true; + return false; } public function saveChunk($x, $z){ diff --git a/src/pocketmine/utils/MainLogger.php b/src/pocketmine/utils/MainLogger.php index 463c9bb7a..90e6ba2cb 100644 --- a/src/pocketmine/utils/MainLogger.php +++ b/src/pocketmine/utils/MainLogger.php @@ -138,7 +138,7 @@ class MainLogger extends \AttachableThreadedLogger{ $errfile = \pocketmine\cleanPath($errfile); $this->log($type, get_class($e).": \"$errstr\" ($errno) in \"$errfile\" at line $errline"); - foreach(($trace = \pocketmine\getTrace($trace === null ? 4 : 0, $trace)) as $i => $line){ + foreach(($trace = @\pocketmine\getTrace($trace === null ? 4 : 0, $trace)) as $i => $line){ $this->debug($line); } }