conn: handle initial error packet correctly #307
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 theCLIENT_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 blackbeam/rust_mysql_common#136