Skip to content
Open
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
8 changes: 7 additions & 1 deletion lib/async/pool/controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,13 @@ def start_gardener
end
ensure
@gardener = nil
self.close

# During cancellation, busy resources will never be released,
# so force-retire everything instead of draining gracefully.
while (resource, _usage = @resources.first)
retire(resource)
end
@available.clear
end
end

Expand Down
20 changes: 20 additions & 0 deletions test/async/pool/controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,26 @@

expect(events).to be == [:acquire, :close, :release, :closed]
end

it "does not deadlock when Sync scope exits with unreleased resources" do
thread = Thread.new do
Sync do
policy = proc{|pool| pool.prune(0)}
pool = subject.new(Async::Pool::Resource, policy: policy)

# Acquire a resource (starts the gardener) but don't release it
pool.acquire

# Let gardener start and enter its wait loop
sleep 0.05
end
end

result = thread.join(5)
thread.kill if result.nil?

expect(result).not.to be_nil
end
end

with "#to_s" do
Expand Down
Loading