mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 17:59:48 +00:00
AsyncTask and AsyncPool no longer tolerate uncaught errors in tasks
Since task execution depends on tasks executing sequentially on a particular worker in some cases (e.g. PopulationTask must be preceded by GeneratorRegisterTask), it doesn't make sense to continue task execution if an error occurs. Moreover, a task crashing may render the whole server unstable, as it leaves the server in an undefined state. This is the same kind of problem we fixed with scheduled tasks in PM3. In versions past, pthreads was unreliable enough that random tasks would crash without an obvious reason, forcing us to accommodate this. I still don't know the origin or frequency of said issues, but I think it's time to rip the band-aid off and solve these problems for real.
This commit is contained in:
@ -39,7 +39,6 @@ use pocketmine\world\format\io\FastChunkSerializer;
|
||||
|
||||
class ChunkRequestTask extends AsyncTask{
|
||||
private const TLS_KEY_PROMISE = "promise";
|
||||
private const TLS_KEY_ERROR_HOOK = "errorHook";
|
||||
|
||||
protected string $chunk;
|
||||
protected int $chunkX;
|
||||
@ -48,10 +47,7 @@ class ChunkRequestTask extends AsyncTask{
|
||||
protected NonThreadSafeValue $compressor;
|
||||
private string $tiles;
|
||||
|
||||
/**
|
||||
* @phpstan-param (\Closure() : void)|null $onError
|
||||
*/
|
||||
public function __construct(int $chunkX, int $chunkZ, Chunk $chunk, CompressBatchPromise $promise, Compressor $compressor, ?\Closure $onError = null){
|
||||
public function __construct(int $chunkX, int $chunkZ, Chunk $chunk, CompressBatchPromise $promise, Compressor $compressor){
|
||||
$this->compressor = new NonThreadSafeValue($compressor);
|
||||
|
||||
$this->chunk = FastChunkSerializer::serializeTerrain($chunk);
|
||||
@ -60,7 +56,6 @@ class ChunkRequestTask extends AsyncTask{
|
||||
$this->tiles = ChunkSerializer::serializeTiles($chunk);
|
||||
|
||||
$this->storeLocal(self::TLS_KEY_PROMISE, $promise);
|
||||
$this->storeLocal(self::TLS_KEY_ERROR_HOOK, $onError);
|
||||
}
|
||||
|
||||
public function onRun() : void{
|
||||
@ -75,17 +70,6 @@ class ChunkRequestTask extends AsyncTask{
|
||||
$this->setResult($this->compressor->deserialize()->compress($stream->getBuffer()));
|
||||
}
|
||||
|
||||
public function onError() : void{
|
||||
/**
|
||||
* @var \Closure|null $hook
|
||||
* @phpstan-var (\Closure() : void)|null $hook
|
||||
*/
|
||||
$hook = $this->fetchLocal(self::TLS_KEY_ERROR_HOOK);
|
||||
if($hook !== null){
|
||||
$hook();
|
||||
}
|
||||
}
|
||||
|
||||
public function onCompletion() : void{
|
||||
/** @var CompressBatchPromise $promise */
|
||||
$promise = $this->fetchLocal(self::TLS_KEY_PROMISE);
|
||||
|
9
src/network/mcpe/cache/ChunkCache.php
vendored
9
src/network/mcpe/cache/ChunkCache.php
vendored
@ -118,14 +118,7 @@ class ChunkCache implements ChunkListener{
|
||||
$chunkZ,
|
||||
$chunk,
|
||||
$this->caches[$chunkHash],
|
||||
$this->compressor,
|
||||
function() use ($chunkHash, $chunkX, $chunkZ) : void{
|
||||
$this->world->getLogger()->error("Failed preparing chunk $chunkX $chunkZ, retrying");
|
||||
|
||||
if(isset($this->caches[$chunkHash])){
|
||||
$this->restartPendingRequest($chunkX, $chunkZ);
|
||||
}
|
||||
}
|
||||
$this->compressor
|
||||
)
|
||||
);
|
||||
|
||||
|
Reference in New Issue
Block a user