-
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
kill queries on timeout #791
Conversation
2c780b2
to
959332b
Compare
959332b
to
9ed2daa
Compare
I think this should be opt-in option, because it creates unexpected connections and it won't work in some environment. And I want to wait adding this feature until next version (v1.4) is tagged. |
connection.go
Outdated
} | ||
|
||
func (mc *mysqlConn) kill() error { | ||
conn, err := mc.d.Open(mc.dsn) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't creating new connection pool! Create mysqlConn directly.
Addtionally, opening new connection should be have short timeout.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree about timeout but didn't catch your idea about connection pool. Here I'm using MySQLDriver.Open method, which returns driver.Conn and error (underlying type of driver.Conn is *mysqlConn)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sorry, I was wrong about the pool.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#705 should be used instead of Driver.Open.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, will use after it merged to master
Killing query is difficult than you think. Apart from load balanced MySQL server, there are many race scenarios. For example:
In this scenario, what should we do? |
Do you mean that timeout shout be used on the query execution stage, but not while response is being sent back to client? |
I just meant there are many race conditions we should care about before merging this. |
Even though MySQL is not clustered, connection can be not unique. Additionally, when MySQL is under very heavy state, many concurrent queries can be timed out at same time. So I think (1) |
(1) 50 ms? |
aea431d
to
1251784
Compare
1251784
to
eabce5d
Compare
Made this feature optional and added tests to check that query is not killed if flag is not activated. |
This comment has been minimized.
This comment has been minimized.
@Sovianum @ceshihao I recommend using timeout by optimizer-hint. It's much safer than this. |
@pjebs Thanks for writing it. My comments:
|
I've improved my design for reverse proxy scenarios for mysql using Unfortunately I wasn't able to find a reliable way to get a unique server identifier for mariadb. @methane Thanks for the feedback. |
@methane is there a path to getting this PR merged from here? While I'm not sure if @Sovianum still needs this feature or has found a workaround, I could really use this feature on an opt-in basis. The MAX_EXECUTION_TIME optimizer hint you refer to doesn't work for my use case -- I'd like to be able to cancel queries other than a SELECT with a timeout. I am currently using KILL QUERY as a workaround, but it is pretty painful to have to add this logic everywhere I want to ensure a query is canceled after it times out. |
At least, new Connector interface should be used. At most one connection should be used for cancelling many queries. |
It definitely should be optional because you need to waste time querying for the connection id. |
I would love to see this functionality added to mysql. I would not mind taking a stab at it. Circuit breaking is an important part of reliable, timely delivery in a microservice world so data stores remain highly available. Is now the right time to add this functionality or are there other high priority refactors in the works that could lead to PRs being closed? |
Description
Added mechanism to kill orphan queries after context timeout.
Used approach is similar to one used in postgres driver: if context is cancelled, new connection is opened and than KILL query is executed.
Query is killed using id of corresponding connection which is saved on initial handshake.
Related issues: #731, #496
Checklist