Conversation
02984ca to
394e992
Compare
|
|
||
| Metrics/BlockLength: | ||
| Exclude: | ||
| - 'spec/**/*.rb' |
There was a problem hiding this comment.
There was a problem hiding this comment.
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.
I think you're after the instance variable here 😄
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 VARIABLESorSHOW MASTER STATUSwe don't want to want that long before they time out due whatever reasons. It'd be nice to have a per-queryread_timeoutoption - 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
querywhich setscurrent_query_optionsand allowread_timeoutas a supported option ofcurrent_query_options.