NetworkSession: defer destructive cleanup until the next session tick() call

this fixes crashes when kicking players during PlayerJoinEvent and various other events.
This commit is contained in:
Dylan K. Taylor 2022-12-24 20:06:00 +00:00
parent 6375139d0b
commit f7d0d16eb3
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -547,13 +547,18 @@ class NetworkSession{
$this->disposeHooks->clear();
$this->setHandler(null);
$this->connected = false;
$this->manager->remove($this);
$this->logger->info("Session closed due to $reason");
$this->invManager = null; //break cycles - TODO: this really ought to be deferred until it's safe
}
}
/**
* Performs actions after the session has been disconnected. By this point, nothing should be interacting with the
* session, so it's safe to destroy any cycles and perform destructive cleanup.
*/
private function dispose() : void{
$this->invManager = null;
}
/**
* Disconnects the session, destroying the associated player (if it exists).
*/
@ -1114,6 +1119,11 @@ class NetworkSession{
}
public function tick() : void{
if(!$this->isConnected()){
$this->dispose();
return;
}
if($this->info === null){
if(time() >= $this->connectTime + 10){
$this->disconnect("Login timeout");