mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-20 20:48:06 +00:00
Use AsyncTask->onError() for chunk task crash tracking
This commit is contained in:
parent
e62bbd4754
commit
3468f006a2
@ -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();
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user