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