Fixed server not stopping after a special crash

This commit is contained in:
Shoghi Cervantes 2014-11-04 17:15:20 +01:00
parent cc7f12739d
commit 79bc1d6c85
4 changed files with 28 additions and 20 deletions

View File

@ -137,7 +137,7 @@ class CrashDump{
$error = $lastExceptionError; $error = $lastExceptionError;
}else{ }else{
$error = (array) error_get_last(); $error = (array) error_get_last();
$error["trace"] = getTrace(4); $error["trace"] = @getTrace(4);
$errorConversion = [ $errorConversion = [
E_ERROR => "E_ERROR", E_ERROR => "E_ERROR",
E_WARNING => "E_WARNING", E_WARNING => "E_WARNING",

View File

@ -1589,7 +1589,6 @@ class Server{
set_exception_handler([$this, "exceptionHandler"]); set_exception_handler([$this, "exceptionHandler"]);
register_shutdown_function([$this, "crashDump"]); register_shutdown_function([$this, "crashDump"]);
register_shutdown_function([$this, "forceShutdown"]);
$this->pluginManager->loadPlugins($this->pluginPath); $this->pluginManager->loadPlugins($this->pluginPath);
@ -1905,6 +1904,7 @@ class Server{
$this->logger->emergency("Crashed while crashing, killing process"); $this->logger->emergency("Crashed while crashing, killing process");
@kill(getmypid()); @kill(getmypid());
} }
} }
/** /**
@ -2002,7 +2002,7 @@ class Server{
"fullFile" => $e->getFile(), "fullFile" => $e->getFile(),
"file" => $errfile, "file" => $errfile,
"line" => $errline, "line" => $errline,
"trace" => getTrace($trace === null ? 3 : 0, $trace) "trace" => @getTrace($trace === null ? 3 : 0, $trace)
]; ];
global $lastExceptionError, $lastError; global $lastExceptionError, $lastError;
@ -2014,7 +2014,11 @@ class Server{
if($this->isRunning === false){ if($this->isRunning === false){
return; 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"); $this->logger->emergency("An unrecoverable error has occurred and the server has crashed. Creating a crash dump");
$dump = new CrashDump($this); $dump = new CrashDump($this);
@ -2022,30 +2026,33 @@ class Server{
if($this->getProperty("auto-report.enabled", true) !== false){ if($this->getProperty("auto-report.enabled", true) !== false){
$report = true;
$plugin = $dump->getData()["plugin"]; $plugin = $dump->getData()["plugin"];
if(is_string($plugin)){ if(is_string($plugin)){
$p = $this->pluginManager->getPlugin($plugin); $p = $this->pluginManager->getPlugin($plugin);
if($p instanceof Plugin and !($p->getPluginLoader() instanceof PharPluginLoader)){ if($p instanceof Plugin and !($p->getPluginLoader() instanceof PharPluginLoader)){
return; $report = false;
} }
}elseif(\Phar::running(true) == ""){ }elseif(\Phar::running(true) == ""){
return; $report = false;
} }
if($dump->getData()["error"]["type"] === "E_PARSE" or $dump->getData()["error"]["type"] === "E_COMPILE_ERROR"){ 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", [ if($report){
"report" => "yes", $reply = Utils::postURL("http://" . $this->getProperty("auto-report.host", "crash.pocketmine.net") . "/submit/api", [
"name" => $this->getName() . " " . $this->getPocketMineVersion(), "report" => "yes",
"email" => "crash@pocketmine.net", "name" => $this->getName() . " " . $this->getPocketMineVersion(),
"reportPaste" => base64_encode($dump->getEncodedData()) "email" => "crash@pocketmine.net",
]); "reportPaste" => base64_encode($dump->getEncodedData())
]);
if(($data = json_decode($reply)) !== false and isset($data->crashId)){ if(($data = json_decode($reply)) !== false and isset($data->crashId)){
$reportId = $data->crashId; $reportId = $data->crashId;
$reportUrl = $data->crashUrl; $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."); $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"; //$dump .= "Memory Usage Tracking: \r\n" . chunk_split(base64_encode(gzdeflate(implode(";", $this->memoryStats), 9))) . "\r\n";
$this->forceShutdown(); $this->forceShutdown();
kill(getmypid()); @kill(getmypid());
exit(1); exit(1);
} }

View File

@ -193,9 +193,10 @@ class McRegion extends BaseLevelProvider{
$chunk = $this->getChunk($x, $z, false); $chunk = $this->getChunk($x, $z, false);
if($chunk instanceof FullChunk and $chunk->unload(false, $safe)){ if($chunk instanceof FullChunk and $chunk->unload(false, $safe)){
unset($this->chunks[Level::chunkHash($x, $z)]); unset($this->chunks[Level::chunkHash($x, $z)]);
return true;
} }
return true; return false;
} }
public function saveChunk($x, $z){ public function saveChunk($x, $z){

View File

@ -138,7 +138,7 @@ class MainLogger extends \AttachableThreadedLogger{
$errfile = \pocketmine\cleanPath($errfile); $errfile = \pocketmine\cleanPath($errfile);
$this->log($type, get_class($e).": \"$errstr\" ($errno) in \"$errfile\" at line $errline"); $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); $this->debug($line);
} }
} }