Unavoidable commands out of sync on interrupt during execute #660
Replies: 1 comment 1 reply
-
Yes. it is the only solution. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Describe the bug
It is well known that MySQL bindings require that results associated with an executed query must all be fetched or discarded before a second query is attempted otherwise the connection will be stuck in a
Commands out sync; you can't run this command now
state.In other words, calling a procedure without fetching all associated results or calling
execute
with multiple statements separated with a;
and trying to reuse the connection for follow up queries will reproduce the state described above. This is fine and expected to be handled bymysqlclient
users.One thing that the library fails to account for though is the fact that an interrupt signal that relies on exceptions (think of
CTRL + C
which results inKeyboardInterupt
or any other signal handler could happen during the blockingdb.query
call and break the symmetry of the_do_get_result
call leaving the connection in an unusable state.When this occurs one might be tempted to write code along the lines of
To keep the connection in a reusable state but that's not possible as
.fetchall()
cannot be called before_do_get_result
andself._executed
is assigned.So my question to you all, is there something that can be done at the
Cursor
level to prevent connections from getting into this state when a non-database exception is raised before_do_get_result
is called or is the only solution to terminate the connection?sleep
function andKeyboardInterrupt
are solely for demonstration and the local reproducibility purposes of this report. In a real life scenario the query could be any query that happens to run at the time an interrupt is signalled by a supervisor in charge of managing Python processes (e.g. think of container orchestration or Celery + Billiard soft limit handling viaSoftTimeLimitExceeded
)Environment
No response
How did you install libmysqlclient libraries?
brew
What version of mysqlclient do you use?
2.20
Docker command to start MySQL server
Minimum but complete code to reproduce
Schema and initial data required to reproduce.
No response
Commands, and any other step required to reproduce your issue.
Run the above Python code as standalone script on in a Python terminal and issue an interrupt to notice how the connection is left in an unusable state.
Beta Was this translation helpful? Give feedback.
All reactions