Skip to content

Commit e49c4b3

Browse files
committed
Merge pull request #706 from carsonreinke/timeout_nil
Allow nil for timeouts instead of casting to zero
2 parents 7a0c653 + fda2f87 commit e49c4b3

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/mysql2/client.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def initialize(opts = {})
3636
when :reconnect, :local_infile, :secure_auth
3737
send(:"#{key}=", !!opts[key]) # rubocop:disable Style/DoubleNegation
3838
when :connect_timeout, :read_timeout, :write_timeout
39-
send(:"#{key}=", opts[key].to_i)
39+
send(:"#{key}=", opts[key]) unless opts[key].nil?
4040
else
4141
send(:"#{key}=", opts[key])
4242
end

spec/mysql2/client_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,12 @@ def run_gc
352352
}.to raise_error(Mysql2::Error)
353353
end
354354

355+
it "should allow nil read_timeout" do
356+
client = Mysql2::Client.new(:read_timeout => nil)
357+
358+
expect(client.read_timeout).to be_nil
359+
end
360+
355361
context "#query" do
356362
it "should let you query again if iterating is finished when streaming" do
357363
@client.query("SELECT 1 UNION SELECT 2", :stream => true, :cache_rows => false).each.to_a

0 commit comments

Comments
 (0)