blackbeam / mysql_async

Asyncronous Rust Mysql driver based on Tokio.
Apache License 2.0
372 stars 113 forks source link

conn: handle initial error packet correctly #307

Closed petrosagg closed 1 month ago

petrosagg commented 1 month ago

During the initial handshake there is the possibility that the server replies with an error. Since this happens before the server has seen a HandshakeResponse it cannot assume anything about our capabilities and therefore its error packet will be sent as if we have none. This means that even if our client has the CLIENT_PROTOCOL_41 flag set it must parse this initial error packet as if it doesn't, which basically boils down to not expecting a SQL state field.

This PR is made up of two commits. The first is a unit test that sets up a fake MySQL server that replies with an error packet. The test is verified to fail on current main. The second commit adds a fix for correctly parsing those initial error packets and makes the test pass.

The behavior of the initial error packet is documented in the "Note:" section here: https://dev.mysql.com/doc/dev/mysql-server/latest/page_protocol_connection_phase.html

Closes https://github.com/blackbeam/rust_mysql_common/issues/136