-
Notifications
You must be signed in to change notification settings - Fork 548
Allow per-query read_timeout #955
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
base: master
Are you sure you want to change the base?
Conversation
02984ca
to
394e992
Compare
|
||
Metrics/BlockLength: | ||
Exclude: | ||
- 'spec/**/*.rb' |
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.
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.
Thanks! This number could be reduced then: https://github.com/kirs/mysql2/blob/b50e1178fe1f8db5fc252a3697b94b42a0f34db2/.rubocop_todo.yml#L24
spec/mysql2/client_spec.rb
Outdated
|
||
it "does not time out on queries under timeout" do | ||
expect do | ||
client.query("select sleep(1)", read_timeout: 2) |
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 think you're after the instance variable here 😄
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.
Thanks @jacobbednarz!
394e992
to
b50e117
Compare
Thank you! Feedback 1: I think you should also change the The comment from when this was added (see 82aa624 and d48846f for the major history of this timeout) suggests it was only useful for blocking functions like mysql_ping, and not any different in the query case. Need to do a little more reading on this. Way under the hood, this MySQL option turns into a Feedback 2: If you're running MySQL 5.7 you can pass an optimizer hint to set a different maximum query time. https://dev.mysql.com/doc/refman/5.7/en/optimizer-hints.html
The benefit of putting the timeout on the server side is that it actually cancels the query, so you get to continue using the client connection without risk that it's still in a query state. |
Thanks for feedback and for the context in timeouts.
|
You're right, I forgot that The inconsistency I want to avoid is someone trying to set a longer read timeout on a per-query basis, and reporting the next bug :) . Maybe just a simple warning if the timeout value on the query is longer than the value on the connection, and then clamping the effective value to the smaller of the two. |
For most of the queries in our Rails app, we allow a higher read timeout since they may legitimately take longer. But for health check queries like
SHOW VARIABLES
orSHOW MASTER STATUS
we don't want to want that long before they time out due whatever reasons. It'd be nice to have a per-queryread_timeout
option - that's what this PR implements!Implementation
I was looking at how waiting for a read timeout works and it was interesting to learn that it's simply waiting for a file descriptor to become available:
This makes me believe that we can leverage the second argument to
query
which setscurrent_query_options
and allowread_timeout
as a supported option ofcurrent_query_options
.