Skip to content
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

Make sure :checkout_timeout and :dead_connection_timeout are numbers #16542

Conversation

seamusabshere
Copy link
Contributor

If :checkout_timeout (or :dead_connection_timeout) is specified with ENV['DATABASE_URL'], then you may get

NoMethodError: undefined method `-' for "5":String
from /Users/myuser/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:182:in `block in wait_poll'

For example:

$ rails c
Loading development environment (Rails 4.1.4)
[1] pry(main)> ENV['DATABASE_URL']
=> "postgres://myuser:@127.0.0.1/mydb?pool=3&checkout_timeout=5"
[2] pry(main)> ActiveRecord::Base.connection_config
=> {:adapter=>"postgresql", :database=>"mydb", :encoding=>"utf8", :min_messages=>"warning", :pool=>"3", :timeout=>5000, :checkout_timeout=>"5", :username=>"myuser", :host=>"127.0.0.1"}
[3] pry(main)> threads = 10.times.map { Thread.new { c = ActiveRecord::Base.connection_pool.checkout; sleep 10 } }
=> [#<Thread:0x00000106332050 sleep>,
 #<Thread:0x00000106331f38 sleep>,
 #<Thread:0x00000106331df8 sleep>,
 #<Thread:0x00000106322240 run>,
 #<Thread:0x00000106322100 run>,
 #<Thread:0x00000106321f98 run>,
 #<Thread:0x00000106321e58 run>,
 #<Thread:0x00000106321d40 run>,
 #<Thread:0x00000106321b88 run>,
 #<Thread:0x000001063219d0 run>]
[4] pry(main)> threads.each(&:join)
NoMethodError: undefined method `-' for "5":String
from /Users/myuser/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:182:in `block in wait_poll'

In this change, I use #to_f instead of #to_i because these timeouts are specified in seconds instead of milliseconds

…eout are numbers

Using #to_f instead of #to_i because they are specified in seconds instead of milliseconds
rafaelfranca added a commit that referenced this pull request Aug 19, 2014
…imeout-from-urls-4-1-stable

Make sure :checkout_timeout and :dead_connection_timeout are numbers
@rafaelfranca rafaelfranca merged commit e1f358d into rails:4-1-stable Aug 19, 2014
rafaelfranca added a commit that referenced this pull request Aug 19, 2014
…imeout-from-urls-4-1-stable

Make sure :checkout_timeout and :dead_connection_timeout are numbers
Conflicts:
	activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants