poggit / libasynql

Asynchronous MySQL access library for PocketMine plugins.
https://poggit.github.io/libasynql
Apache License 2.0
132 stars 44 forks source link

libasynql\base\QueueShutdownException: "You cannot schedule a query on an invalidated queue." #46

Closed Endermanbugzjfc closed 4 years ago

Endermanbugzjfc commented 4 years ago

Describe the bug

A clear and concise description of what the bug is.

> mw unload lobby-1
[14:53:24] [Server thread/INFO]: Unloading world "endermanbugzjfc"
[14:53:24] [Server thread/INFO]: [MultiWorld] World unloaded.
> mw load lobby-1
[14:53:27] [Server thread/INFO]: Preparing world "endermanbugzjfc"
[14:53:27] [Server thread/CRITICAL]: poggit\libasynql\base\QueueShutdownException: "You cannot schedule a query on an invalidated queue." (EXCEPTION) in "/home/container/virions/libasynql.phar/src/poggit/libasynql/base/QuerySendQueue" at line 40

Sample code

Level unload event:

public function onPMMPLevelUnloadEvent(\pocketmine\event\level\LevelUnloadEvent $e) : void {
    $w = $e->getLevel();
    if (substr($w->getFolderName(), 0, 5) !== 'lobby') return;
    if ($this->lobbydb instanceof DataConnector) $this->lobbydb->close();
}

Level load event:

public function onPMMPLevelLoadEvent(\pocketmine\event\level\LevelLoadEvent $e) : void {
    $w = $e->getLevel();
    if (substr($w->getFolderName(), 0, 5) !== 'lobby') return;
    $w->stopTime();
    $this->lobbydb = libasynql::create($this->main, self::CONNECTION, self::SQL_FILE);
    $this->lobbydb->executeGeneric(self::SQL_SCRIPTS['init']['parkour']);
    $this->lobbydb->waitAll();
}

Expected behavior I have a sqlite for the lobby level. So basically I want to make it when I load the level the database will be connected also when the level unloads, it closes. However, it only worked at the first load. Although I added the code above to close the connection, the second time it loads, it just gave me the error above.

Environment OS: Linux PocketMine version: 3.15.0

SOF3 commented 4 years ago

It seems that you are still using $this->lobbydb after unsetting. Try $this->lobbydb = null; after closing it.