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

Fix reaper exhausting the queue #188

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/connection_pool/timed_stack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ def reap_idle_connections(idle_seconds, reap_start_time, &reap_block)
while idle_connections?(idle_seconds, reap_start_time)
conn, _last_checked_out = @que.shift
reap_block.call(conn)
# Decrement created unless this is a no create stack
@created -= 1 unless @max == 0
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need a mutex or synchronization?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method operates within a mutex block, so it's clear here.

However, looking over how this is currently setup, there could be resource contention issues with the reaper trying to close connections when something else decides it wants a connection from the pool. I think I'll take a quick stab at trying to improve that in another PR. This one is nice and simple and fixes an actual bug.

end
end

Expand Down
14 changes: 13 additions & 1 deletion test/test_connection_pool_timed_stack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,18 @@ def test_reap
assert_empty @stack
end

def test_reap_full_stack
stack = ConnectionPool::TimedStack.new(1) { Object.new }
stack.push stack.pop

stack.reap(0) do |object|
nil
end

# Can still pop from the stack after reaping all connections
refute_nil stack.pop
end

def test_reap_large_idle_seconds
@stack.push Object.new

Expand Down Expand Up @@ -250,7 +262,7 @@ def test_reap_with_multiple_connections_and_zero_idle_seconds
end

assert_equal [conn1, conn2], called
assert_empty stack
assert_equal 0, stack.idle
end

def test_reap_with_multiple_connections_and_idle_seconds_outside_range
Expand Down
Loading