提交 700639e4 编写于 作者: R Ryuta Kamizono

Fix the race condition caused by `with_new_connections_blocked`

`with_new_connections_blocked` was introduced at #14938.
But the method sometimes causes `@new_cons_enabled = false` then never
toggled to true.
上级 3a558aa2
......@@ -350,8 +350,7 @@ def initialize(spec)
# currently in the process of independently establishing connections to the DB.
@now_connecting = 0
# A boolean toggle that allows/disallows new connections.
@new_cons_enabled = true
@new_cons_blocks = 0
@available = ConnectionLeasingQueue.new self
end
......@@ -700,13 +699,10 @@ def checkout_for_exclusive_access(checkout_timeout)
end
def with_new_connections_blocked
previous_value = nil
synchronize do
previous_value, @new_cons_enabled = @new_cons_enabled, false
end
synchronize { @new_cons_blocks += 1 }
yield
ensure
synchronize { @new_cons_enabled = previous_value }
synchronize { @new_cons_blocks -= 1 }
end
# Acquire a connection by one of 1) immediately removing one
......@@ -758,7 +754,7 @@ def try_to_checkout_new_connection
# and increment @now_connecting, to prevent overstepping this pool's @size
# constraint
do_checkout = synchronize do
if @new_cons_enabled && (@connections.size + @now_connecting) < @size
if @new_cons_blocks.zero? && (@connections.size + @now_connecting) < @size
@now_connecting += 1
end
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册