-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Context cancelling cause close connection without sending COMM_QUIT for authenticated connection #1648
Comments
@methane Would you be able to confirm that this is the intended behavior? Is it a bug? |
It is intended behavior, not a bug. On the other hand, I do not against sending COM_QUIT on cancel. I will consider about it is really safe or not. |
@methane thanks for reply
I think to properly close an authenticated connection, we need to send a COMM_QUIT packet to the MySQL server. This will prevent the MySQL server from treating the connection as aborted, which can negatively impact performance monitoring. (I spend a lot of time investigating frequent MySQL connection aborts.)
I agree that the SQL driver should send COMM_QUIT on cancel in a safe and reliable manner.
Did you mean that the database query will run despite context cancel occurred? What are the best practices for using context in queries, Would you be able to share any example, the case we should context or not. |
Yes. MySQL protocol doesn't provide safe&robust way to cancel running query.
I will add some option for context cancellation next year (e.g. ignore context cancel at all, safe for MariaDB, and not-safe & use it your own risk version). But I cannot promise it. |
Issue description
startWatcher() watches the context provided by the Go client. When context cancellation occurs, this method only cleanup() the connection without sending COMM_QUIT, regardless of whether the connection has already been authenticated or not.
Without COMM_QUIT, MySQL Server will abort authenticated clients, and increase Aborted_clients metric.
Related code
Current handling when context cancel:
mysql/connection.go
Lines 439 to 441 in c9f41c0
But cleanup() is only called before auth or on auth failure
mysql/connection.go
Lines 134 to 138 in c9f41c0
Close() should be called if the connection has been authenticated successfully with sending COMM_QUIT to MySQL server
Error log
Configuration
Driver version (or git SHA):
1.8.1
Go version: run
go version
in your consoleServer version: E.g. MySQL 5.6, MariaDB 10.0.20
Server OS: E.g. Debian 8.1 (Jessie), Windows 10
The text was updated successfully, but these errors were encountered: