-
Notifications
You must be signed in to change notification settings - Fork 335
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
Improve command timeout handling #455
Comments
I initially started implementing command timeouts that way, but changed my mind: #67 (comment) The primary reason the command timeout exists is to stop the client hanging forever if there is a network failure; it is not about cancelling a long-running command. (Use |
If I can unambiguously detect MariaDB, this seems like a great enhancement to add. (I looked into MySQL's
This is unreliable in the face of load-balanced servers, proxies, or network partitions. However... we could try |
you can unambigously detect MariaDB. It has -MariaDB in server version string. The "real" version is also prefixed by 5.5.5- prefix , due to https://jira.mariadb.org/browse/MDEV-4088 . MariaDB-aware Connectors strip off that prefix : https://jira.mariadb.org/browse/CONC-21 https://jira.mariadb.org/browse/CONJ-32 |
MySQL-protocol aware Proxies are supposed to support KILL QUERY and KILL CONNECTION, because those are quite widely used among all connectors. |
"The primary reason the command timeout exists is to stop the client hanging forever if there is a network failure; it is not about cancelling a long-running command" This is usually worked around not with query timeout, but with KeepAlive (with keepalive parameters), e.g SIO_KEEPALIVE_VALS on Windows, https://msdn.microsoft.com/en-us/library/system.net.sockets.iocontrolcode(v=vs.110).aspx . See also https://github.com/dotnet/corefx/issues/25040 |
Investigate what the Connector/J |
Similar issue being discussed for npgsql (which might provide an implementation approach to copy): npgsql/npgsql#1567. |
+999! This feature is badly needed. Setting it on a per connection level something like |
The current situation for MySqlConnector is very similar to what @roji describes for npgsql, with the same good and bad points: npgsql/npgsql#1567 (comment) Based on recent work in npgsql and recent feedback here, I'm proposing the following changes:
There's an open question of whether exceptions should be unified between sync and async cancellation (cf. npgsql/npgsql#1146 (comment) ff). Under this proposal |
Wouldn't it be better to just set |
Yeah, we also raised this at some point (but haven't implemented it). @bgrainger if this makes sense to you, we can implement the same on the Npgsql side. |
It feels a little "weird" to me to say "set @roji it looks like you were maybe discussing that here? npgsql/npgsql#3173 (comment) Would you implement it the following way, or switch the meanings?
|
I do agree with @vonzshik that an additional connection string flag for managing whether cancellation occurs is not needed, and that CancellationTimeout should probably be sufficient. I generally try to avoid connection string parameter explosion (there already are many and it's confusing...), and I suspect disabling cancellation is a very rare edge which doesn't deserve a parameter. @bgrainger I do think it would be more logical/consistent for zero to mean "wait 0 seconds before closing the socket" (just like one means "wait 1 second before closing the socket"). But your proposal makes the meaning of zero is the same as what it is for CommandTimeout (don't timeout at all), which is consistent in another, probably more important way. So I vote for your proposal - @vonzshik any additional thoughts on this? |
In a context of |
OK, so I think we're all saying the same thing. @vonzshik would you like to open an issue to implement the above behavior in Npgsql too? |
Done. |
Edited the MySqlConnector proposal above to document the expected behaviour of |
The query timeout handling in MySqlConnection can be simplified a lot, if it could use server support for query timeouts. E.g in MariaDB 10.1+ you can using per-statement max_query_time , described in https://mariadb.com/kb/en/library/aborting-statements/ . There is a max_statement_time session variable (double) for max time, measured in seconds
MySQL supports this functionality but chose to implement it slightly differently, and in a limited way (variable name is max_execution_time, and it does only work for SELECTs).
Traditional way to implement statement timeouts in other connectors (preceding server support) , was to start a timer task, right before execution of the query. If the task fires, i would create issue "KILL QUERY " from another connection. If query finishes before the timeout , the timer task would be canceled. For MySqlConnector, I feel that even this handling would simplify IO code, which currently relies on socket or stream timeouts( yet still has timer queues for async)
The text was updated successfully, but these errors were encountered: