amphp / mysql

An async MySQL client for PHP, optimizing database interactions with efficient non-blocking capabilities. Perfect for responsive, high-performance applications.
Other
359 stars 63 forks source link

Fix connection pool recovery #31

Closed marcioAlmada closed 7 years ago

marcioAlmada commented 7 years ago

I've managed to fix these 2 little issues in the call graph related to connection pool recovery, which is good enough for 90% use cases.

But I still could not handle the situation when prepared statements were prepared before the database was restarted.

Scenario:

Error:

Amp\\Mysql\\QueryException: MySQL error (1243): #HY000 Unknown prepared statement handler (1) given to mysqld_stmt_execute
Current query was SELECT
    [...] omitted [..]
 in /vendor/amphp/mysql/lib/Processor.php:393
 Stack trace:
 #0 /vendor/amphp/mysql/lib/Processor.php(1097): Amp\\Mysql\\Processor->handleError('\\xFF\\xDB\\x04#HY000Unknow...')
 #1 /vendor/amphp/mysql/lib/Processor.php(931): Amp\\Mysql\\Processor->parsePayload('\\xFF\\xDB\\x04#HY000Unknow...')
#2 /vendor/amphp/amp/lib/UvReactor.php(424): Amp\\Mysql\\Processor->onRead('0000000016aad06...', Resource id #274, NULL)
#3 /vendor/amphp/amp/lib/UvReactor.php(401): Amp\\UvReactor->invokePollWatcher(Object(stdClass))
#4 [internal function]: Amp\\UvReactor->Amp\\{closure}(Resource id #280, 0, 1, Resource id #274)
#5 /vendor/amphp/amp/lib/UvReactor.php(93): uv_run(Resource id #60, 1)
#6 /vendor/amphp/amp/lib/functions.php(46): Amp\\UvReactor->run(Object(Closure))
#7 /vendor/amphp/aerys/bin/aerys(106): Amp\\run(Object(Closure))
#8 {main}

But then I wonder if it should be really possible to reuse a prepared statement after mysql is restarted or if Amp\Mysql should handle this transparently so users won't need to 🤔

mention-bot commented 7 years ago

@marcioAlmada, thanks for your PR! By analyzing the history of the files in this pull request, we identified @bwoebi and @rdlowrey to be potential reviewers.

marcioAlmada commented 7 years ago

Relates to #30

@bwoebi perhaps you could give me a hint here.

kelunik commented 7 years ago

MySQL should handle that transparently.

bwoebi commented 7 years ago

Yes, amp/mysql should handle that transparently. You do not really want, in a long running application take care yourself at every statement invocation whether connection has been lost or not.