Skip to content

Instantly share code, notes, and snippets.

@mjacobus
Created March 5, 2014 19:32
Show Gist options
  • Save mjacobus/9374779 to your computer and use it in GitHub Desktop.
Save mjacobus/9374779 to your computer and use it in GitHub Desktop.
module ActiveRecord
module ConnectionAdapters
class ConnectionPool
class Queue
# Waits on the queue up to +timeout+ seconds, then removes and
# returns the head of the queue.
def wait_poll(timeout)
@num_waiting += 1
t0 = Time.now
elapsed = 0
loop do
@cond.wait(timeout - elapsed)
return remove if any?
elapsed = Time.now - t0
if elapsed >= timeout
msg = 'could not obtain a database connection within %0.3f seconds (waited %0.3f seconds)' %
[timeout, elapsed]
raise ConnectionTimeoutError, msg
end
end
ensure
@num_waiting -= 1
end
# The original method is above. This is the "fix"
def wait_poll(timeout)
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment