-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Handling of MariaDB ER_CONNECTION_KILLED error packet #526
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
Comments
+1 |
methane
added a commit
to methane/PyMySQL
that referenced
this issue
Jan 12, 2017
methane
added a commit
to methane/PyMySQL
that referenced
this issue
Jan 12, 2017
methane
added a commit
to methane/PyMySQL
that referenced
this issue
Jan 13, 2017
methane
added a commit
that referenced
this issue
Jan 13, 2017
Raise SERVER_LOST error for MariaDB's shutdown packet fixes #526
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
This is a bit of quirky corner case. Under MariaDB during normal mysqld shutdown an error packet can be sent to the client of the form:
\x1e\x00\x00\x00\xff\x87\x07#70100Connection was killed
With a TCP connection this might be pending on the socket after a query was sent, resulting in pymysql failing with
pymysql.err.InternalError: Packet sequence number wrong - got 0 expected 1
If the connection is not immediately closed this might result in further Packet sequence errors as the remaining bytes of this packet are read on subsequent queries but related to this same initial cause (e.g.
Packet sequence number wrong - got 35 expected 1
mapping to the '#' character,got 48 expected 1
mapping to the '0' character, and so on as some applications were failing to discard and was subsequently reusing the connection after hitting an InternalError).FWIW, I was unable to reproduce this under Oracle/MySQL 5.6+ so perhaps this is just a quirk of MariaDB. This error packet also does not get sent under normal
KILL [CONNECTION]
conditions on MariaDB - only after a normal shutdown. This case will also not manifest if a local unix socket connection (rather than TCP) is used - the socket io will error out before reading this error packet.Expected Behavior
Expected: a dbapi error (ideally OperationalError) with the contents of the error packet. For comparison, MySQL-python, in contrast, always seems to fail with
OperationalError: (2013, 'Lost connection to MySQL server during query')
.Current Behavior
InternalError indicating a packet sequence error
Possible Solution
Read the error packet and follow the normal failure path - ideally mapping this 1927 error to an OperationalError exception. Dealing with this while retaining the check on packet sequence number is a bit awkward.
Executable script to reproduce (for bugs)
Tracebacks (for bugs)
Context
I encountered this in a openstack test environment after restarting a MariaDB backend database - the existing (sqlalchemy pooled) connections all failed with "Packet sequence number wrong" errors. The error was confusing and I initially suspected a service of mishandling connections (which is usually the case), but this happened across every project with an open database connection on an idle test environment.
The internal error here with this message was not handled elegantly and the error packet messages makes it clear why things failed, at least. Remapping this error to an OperationalError exception leads to much more elegant default recovery behavior for some environments.
Your Environment
The text was updated successfully, but these errors were encountered: