Use AsyncTask->onError() for chunk task crash tracking

This commit is contained in:
Dylan K. Taylor 2019-04-17 16:00:17 +01:00
parent e62bbd4754
commit 3468f006a2
2 changed files with 16 additions and 11 deletions

View File

@ -2440,14 +2440,9 @@ class Level implements ChunkManager, Metadatable{
Level::getXZ($index, $x, $z); Level::getXZ($index, $x, $z);
if(isset($this->chunkSendTasks[$index])){ if(isset($this->chunkSendTasks[$index])){
if($this->chunkSendTasks[$index]->isCrashed()){
unset($this->chunkSendTasks[$index]);
$this->server->getLogger()->error("Failed to prepare chunk $x $z for sending, retrying");
}else{
//Not ready for sending yet //Not ready for sending yet
continue; continue;
} }
}
if(isset($this->chunkCache[$index])){ if(isset($this->chunkCache[$index])){
$this->sendCachedChunk($x, $z); $this->sendCachedChunk($x, $z);
@ -2485,7 +2480,12 @@ class Level implements ChunkManager, Metadatable{
$this->server->getLogger()->debug("Dropped prepared chunk $x $z due to world not loaded"); $this->server->getLogger()->debug("Dropped prepared chunk $x $z due to world not loaded");
} }
}); });
$this->server->getAsyncPool()->submitTask($task = new ChunkRequestTask($x, $z, $chunk, $promise)); $this->server->getAsyncPool()->submitTask($task = new ChunkRequestTask($x, $z, $chunk, $promise, function() use($index, $x, $z){
if(isset($this->chunkSendTasks[$index])){
unset($this->chunkSendTasks[$index]);
$this->server->getLogger()->error("Failed to prepare chunk $x $z for sending, retrying");
}
}));
$this->chunkSendTasks[$index] = $task; $this->chunkSendTasks[$index] = $task;
$this->timings->syncChunkSendPrepareTimer->stopTiming(); $this->timings->syncChunkSendPrepareTimer->stopTiming();

View File

@ -37,14 +37,14 @@ class ChunkRequestTask extends AsyncTask{
protected $compressionLevel; protected $compressionLevel;
public function __construct(int $chunkX, int $chunkZ, Chunk $chunk, CompressBatchPromise $promise){ public function __construct(int $chunkX, int $chunkZ, Chunk $chunk, CompressBatchPromise $promise, ?\Closure $onError = null){
$this->compressionLevel = NetworkCompression::$LEVEL; $this->compressionLevel = NetworkCompression::$LEVEL;
$this->chunk = $chunk->networkSerialize(); $this->chunk = $chunk->networkSerialize();
$this->chunkX = $chunkX; $this->chunkX = $chunkX;
$this->chunkZ = $chunkZ; $this->chunkZ = $chunkZ;
$this->storeLocal($promise); $this->storeLocal(["promise" => $promise, "errorHook" => $onError]);
} }
public function onRun() : void{ public function onRun() : void{
@ -59,9 +59,14 @@ class ChunkRequestTask extends AsyncTask{
$this->setResult(NetworkCompression::compress($stream->getBuffer(), $this->compressionLevel)); $this->setResult(NetworkCompression::compress($stream->getBuffer(), $this->compressionLevel));
} }
public function onError() : void{
$hook = $this->fetchLocal()["errorHook"];
$hook();
}
public function onCompletion() : void{ public function onCompletion() : void{
/** @var CompressBatchPromise $promise */ /** @var CompressBatchPromise $promise */
$promise = $this->fetchLocal(); $promise = $this->fetchLocal()["promise"];
$promise->resolve($this->getResult()); $promise->resolve($this->getResult());
} }
} }