Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

conn: handle initial error packet correctly #307

Merged
merged 2 commits into from
May 28, 2024

Conversation

petrosagg
Copy link
Contributor

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 blackbeam/rust_mysql_common#136

If we haven't completed the hashshake the server will not be aware of our
capabilities and so its will packets behave as if we have none. This is necessary to
correcly parse an initial error packet which never contains an SQL State field even
if the client capabilities will eventually contain CLIENT_PROTOCOL_41.

https://dev.mysql.com/doc/dev/mysql-server/latest/page_protocol_connection_phase.html

Signed-off-by: Petros Angelatos <[email protected]>
@petrosagg petrosagg force-pushed the initial-error-packet branch from 32e9b6d to 4bf929a Compare May 23, 2024 10:25
@blackbeam blackbeam merged commit 125aebe into blackbeam:master May 28, 2024
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Regression: Initial error packet ignored after #114
2 participants