poggit / libasynql

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

Thread crashing instead of returning errors. #85

Closed Xd-pro closed 11 months ago

Xd-pro commented 2 years ago

Describe the bug

Stack trace:
#0 [internal function]: pocketmine\errorhandler\ErrorToExceptionHandler::handle(2, 'SQLite3Stmt::ex...', 'D:\\projects\\poc...', 89)
#1 D:\projects\pocketmine-dev-env-new\virions\libasynql\src\poggit\libasynql\sqlite3\Sqlite3Thread.php(89): SQLite3Stmt->execute()
#2 D:\projects\pocketmine-dev-env-new\virions\libasynql\src\poggit\libasynql\base\SqlSlaveThread.php(88): poggit\libasynql\sqlite3\Sqlite3Thread->executeQuery(Object(SQLite3), 2, 'INSERT\nINTO pla...', Array)
#3 phar://D:/projects/pocketmine-dev-env-new/PocketMine-MP.phar/src/thread/CommonThreadPartsTrait.php(93): poggit\libasynql\base\SqlSlaveThread->onRun()
#4 [internal function]: pocketmine\thread\Thread->run()
#5 {main}
  thrown in D:\projects\pocketmine-dev-env-new\virions\libasynql\src\poggit\libasynql\sqlite3\Sqlite3Thread.php on line 89

Sample code Query:

INSERT
INTO players (xuid, ip) 
VALUES (:xuid, :ip)

Table:

CREATE TABLE IF NOT EXISTS players (
    xuid VARCHAR(255) NOT NULL PRIMARY KEY ON CONFLICT ABORT,
    ip VARCHAR(255) NOT NULL,
    permBanned BOOLEAN NOT NULL DEFAULT FALSE,
    unbanAt INT NOT NULL DEFAULT 0,
    warns INT NOT NULL DEFAULT 0
)

Expected behavior Errors would be returned in the onError function.

Environment OS: Windows PocketMine version: 4.7.0 / 1.19.20

Endermanbugzjfc commented 2 years ago

Describe the bug

Stack trace:
#0 [internal function]: pocketmine\errorhandler\ErrorToExceptionHandler::handle(2, 'SQLite3Stmt::ex...', 'D:\\projects\\poc...', 89)
#1 D:\projects\pocketmine-dev-env-new\virions\libasynql\src\poggit\libasynql\sqlite3\Sqlite3Thread.php(89): SQLite3Stmt->execute()
#2 D:\projects\pocketmine-dev-env-new\virions\libasynql\src\poggit\libasynql\base\SqlSlaveThread.php(88): poggit\libasynql\sqlite3\Sqlite3Thread->executeQuery(Object(SQLite3), 2, 'INSERT\nINTO pla...', Array)
#3 phar://D:/projects/pocketmine-dev-env-new/PocketMine-MP.phar/src/thread/CommonThreadPartsTrait.php(93): poggit\libasynql\base\SqlSlaveThread->onRun()
#4 [internal function]: pocketmine\thread\Thread->run()
#5 {main}
  thrown in D:\projects\pocketmine-dev-env-new\virions\libasynql\src\poggit\libasynql\sqlite3\Sqlite3Thread.php on line 89

Sample code Query:

INSERT
INTO players (xuid, ip) 
VALUES (:xuid, :ip)

Table:

CREATE TABLE IF NOT EXISTS players (
  xuid VARCHAR(255) NOT NULL PRIMARY KEY ON CONFLICT ABORT,
  ip VARCHAR(255) NOT NULL,
  permBanned BOOLEAN NOT NULL DEFAULT FALSE,
  unbanAt INT NOT NULL DEFAULT 0,
  warns INT NOT NULL DEFAULT 0
)

Expected behavior Errors would be returned in the onError function.

Environment OS: Windows PocketMine version: 4.7.0 / 1.19.20

What is the error message above the stack trace?

Xd-pro commented 2 years ago
Fatal error: Uncaught ErrorException: SQLite3Stmt::execute(): Unable to execute statement: UNIQUE constraint failed: players.xuid in D:\projects\pocketmine-dev-env-new\virions\libasynql\src\poggit\libasynql\sqlite3\Sqlite3Thread.php:89
Xd-pro commented 2 years ago

Wrapping the code that runs the query in a try/catch does nothing.

SOF3 commented 2 years ago

related: #71

ZoumiSurGithub commented 1 year ago

Hello, when do you plan to release an update (containing the bug fix)?

ZoumiSurGithub commented 1 year ago

I've done some research and it seems that it's the synchronised used to wait for responses during the waitAll that's blocking everything, when there's a crash, and we close the server with a waitAll to wait for all the query responses, the synchronised loops around without returning anything.

SOF3 commented 1 year ago

It is simply because the thread does not try to catch errors, thus never sending SqlErrorResult properly

ZoumiSurGithub commented 1 year ago

It is simply because the thread does not try to catch errors, thus never sending SqlErrorResult properly

When do you plan to solve this problem?

SOF3 commented 1 year ago

if anyone sends a pull request to fix it

cherrychip8293 commented 1 year ago

if anyone sends a pull request to fix it

When will the problem be solved?