提交 e4dc3035 编写于 作者: A Aaron Patterson

Merge pull request #13981 from Fortisque/kevin/postgresql_reaper_threadsafe

Reaper has access to threadsafe active? call
......@@ -393,7 +393,7 @@ def reap
synchronize do
stale = Time.now - @dead_connection_timeout
connections.dup.each do |conn|
if conn.in_use? && stale > conn.last_use && !conn.active?
if conn.in_use? && stale > conn.last_use && !conn.active_threadsafe?
remove conn
end
end
......
......@@ -262,6 +262,12 @@ def disable_referential_integrity
def active?
end
# Adapter should redefine this if it needs a threadsafe way to approximate
# if the connection is active
def active_threadsafe?
active?
end
# Disconnects from the database if already connected, and establishes a
# new connection with the database. Implementors should call super if they
# override the default implementation.
......
......@@ -586,11 +586,16 @@ def clear_cache!
# Is this connection alive and ready for queries?
def active?
@connection.connect_poll != PG::PGRES_POLLING_FAILED
@connection.query 'SELECT 1'
true
rescue PGError
false
end
def active_threadsafe?
@connection.connect_poll != PG::PGRES_POLLING_FAILED
end
# Close then reopen the connection.
def reconnect!
super
......
......@@ -142,7 +142,7 @@ def test_reap_inactive
connections = @pool.connections.dup
connections.each do |conn|
conn.extend(Module.new { def active?; false; end; })
conn.extend(Module.new { def active_threadsafe?; false; end; })
end
@pool.reap
......
......@@ -69,7 +69,7 @@ def test_connection_pool_starts_reaper
conn = pool.checkout
count = pool.connections.length
conn.extend(Module.new { def active?; false; end; })
conn.extend(Module.new { def active_threadsafe?; false; end; })
while count == pool.connections.length
Thread.pass
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册