mirror of
https://gitea.invidious.io/iv-org/shard-crystal-db.git
synced 2024-08-15 00:53:32 +00:00
fix(pool): returning closed resources to the pool (#154)
This commit is contained in:
parent
bf5ca75d1a
commit
6dc3f2dd6f
2 changed files with 20 additions and 1 deletions
|
@ -190,6 +190,23 @@ describe DB::Pool do
|
|||
all[2].closed?.should be_false
|
||||
end
|
||||
|
||||
it "should not return closed resources to the pool" do
|
||||
pool = DB::Pool.new(max_pool_size: 1, max_idle_pool_size: 1) { Closable.new }
|
||||
|
||||
# pool size 1 should be reusing the one resource
|
||||
resource1 = pool.checkout
|
||||
pool.release resource1
|
||||
resource2 = pool.checkout
|
||||
resource1.should eq resource2
|
||||
|
||||
# it should not return a closed resource to the pool
|
||||
resource2.close
|
||||
pool.release resource2
|
||||
|
||||
resource2 = pool.checkout
|
||||
resource1.should_not eq resource2
|
||||
end
|
||||
|
||||
it "should create resource after max_pool was reached if idle forced some close up" do
|
||||
all = [] of Closable
|
||||
pool = DB::Pool.new(max_pool_size: 3, max_idle_pool_size: 1) { Closable.new.tap { |c| all << c } }
|
||||
|
|
|
@ -141,7 +141,9 @@ module DB
|
|||
idle_pushed = false
|
||||
|
||||
sync do
|
||||
if can_increase_idle_pool
|
||||
if resource.responds_to?(:closed?) && resource.closed?
|
||||
@total.delete(resource)
|
||||
elsif can_increase_idle_pool
|
||||
@idle << resource
|
||||
if resource.responds_to?(:after_release)
|
||||
resource.after_release
|
||||
|
|
Loading…
Reference in a new issue