friends-of-reactphp / mysql

Async MySQL database client for ReactPHP.
MIT License
331 stars 66 forks source link

Fix parsing ERR after result set #158

Closed clue closed 1 year ago

clue commented 1 year ago

This changeset fixes parsing an ERR response after a result set. Previously, this would trigger a parser error that would corrupt the entire connection ("Not enough data in buffer").

This error situation is a bit harder to reproduce. For example, this can be triggered in a connection by invoking a KILL QUERY n query from a second connection. Errors for invalid queries (SELECT unknown) would still trigger the existing logic.

In the following diagram, we already supported the transition from COM_QUERY_RESPONSE to ERR just fine. We now also support the transition from ROW/EOF to ERR:

graphviz-3ab2ba81081a7f3cc556d11fd09f50341bba6f15

From https://dev.mysql.com/doc/internals/en/com-query-response.html#text-resultset

Together with the analysis in ticket #123, you're looking at ~8 hours of work, enjoy!

Refs #123

clue commented 1 year ago

This error situation is a bit harder to reproduce. For example, this can be triggered in a connection by invoking a KILL QUERY n query from a second connection. Errors for invalid queries (SELECT unknown) would still trigger the existing logic.

This can also be reproduced with a simple EXPLAIN SELECT * FROM dual statement as per per https://dev.mysql.com/doc/internals/en/err-instead-of-eof.html. Any other SELECT 1 statement after this query would previously fail and now works as expected. The SELECT * FROM dual statement (without EXPLAIN) returns a proper error without a result set header, so any following statements already work in either case.