-
Notifications
You must be signed in to change notification settings - Fork 557
Allow nil for timeouts instead of casting to zero #706
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
Conversation
lib/mysql2/client.rb
Outdated
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.
The trailing parens on nil? are not needed.
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.
.nil? ? nil : looks weird to me, I will change it though.
|
Yes, I think you're right. Nice catch! |
3f6bb13 to
0bc7de6
Compare
|
@sodabrew this should be good to go, let me know otherwise. |
lib/mysql2/client.rb
Outdated
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.
Perhaps we should drop the to_i entirely.
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.
Aha – it's due to accepting String values from URI params without explicit conversion. #313
|
Unit tests are failing at: Which is in code here: static VALUE set_read_timeout(VALUE self, VALUE value) {
long int sec;
Check_Type(value, T_FIXNUM);
sec = FIX2INT(value);
if (sec < 0) {
rb_raise(cMysql2Error, "read_timeout must be a positive integer, you passed %ld", sec);
}
/* Set the instance variable here even though _mysql_client_options
might not succeed, because the timeout is used in other ways
elsewhere */
rb_iv_set(self, "@read_timeout", value);
return _mysql_client_options(self, MYSQL_OPT_READ_TIMEOUT, value);
}Since the default timeout value is nil, it means that the underlying code should also allow assigning nil. But I don't see that MySQL can actually accept a non-positive-Integer value for this setting: https://dev.mysql.com/doc/refman/5.5/en/mysql-options.html This suggests to me that, for this option, nil means "just leave this at the default" and so we shouldn't even pass the value through from the Client#initialize if the value is nil. |
|
Not sure how I missed my own test failing. Maybe just a simple |
|
I think this would be OK. I do feel a little weird that once you set a non-nil value, you can't set it back to nil, but it's definitely better than the error case you're seeing. send(:"#{key}=", opts[key].to_i) unless opts[key].nil? |
0bc7de6 to
73e1edd
Compare
|
Fixed plus rebase. I can't see anything from Travis though, it oddly just says "There was an error while loading data" |
|
Travis had a service failure earlier today, and is still stuck/behind on
the queue. Seems like it will be a few more hours.
|
|
Travis running again and tests are passing. RuboCop picked up this lint warning: |
73e1edd to
fda2f87
Compare
|
How can I get Travis fixed on this? I still see it as pending. |
Allow nil for timeouts instead of casting to zero
The only problem I can see is that the default
connect_timeoutwould not be used if set to nil in theopts.