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,13 +2440,8 @@ class Level implements ChunkManager, Metadatable{
Level::getXZ($index, $x, $z);
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
continue;
}
//Not ready for sending yet
continue;
}
if(isset($this->chunkCache[$index])){
@ -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->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->timings->syncChunkSendPrepareTimer->stopTiming();

View File

@ -37,14 +37,14 @@ class ChunkRequestTask extends AsyncTask{
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->chunk = $chunk->networkSerialize();
$this->chunkX = $chunkX;
$this->chunkZ = $chunkZ;
$this->storeLocal($promise);
$this->storeLocal(["promise" => $promise, "errorHook" => $onError]);
}
public function onRun() : void{
@ -59,9 +59,14 @@ class ChunkRequestTask extends AsyncTask{
$this->setResult(NetworkCompression::compress($stream->getBuffer(), $this->compressionLevel));
}
public function onError() : void{
$hook = $this->fetchLocal()["errorHook"];
$hook();
}
public function onCompletion() : void{
/** @var CompressBatchPromise $promise */
$promise = $this->fetchLocal();
$promise = $this->fetchLocal()["promise"];
$promise->resolve($this->getResult());
}
}