Skip to content

Commit b88d171

Browse files
committed
Merge pull request #615 from estolfo/RUBY-908-timeout
RUBY-908 Don't checkin nil connection back to the pool
2 parents 35408d2 + 6742488 commit b88d171

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

lib/mongo/server/connection_pool.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def with_connection
9898
connection = checkout
9999
yield(connection)
100100
ensure
101-
checkin(connection)
101+
checkin(connection) if connection
102102
end
103103
end
104104

spec/mongo/server/connection_pool_spec.rb

+27
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,31 @@
117117
expect(pool.inspect).to include(pool.__send__(:queue).inspect)
118118
end
119119
end
120+
121+
describe '#with_connection' do
122+
123+
let(:server) do
124+
Mongo::Server.new(address, Mongo::Event::Listeners.new, ssl: SSL)
125+
end
126+
127+
let(:pool) do
128+
described_class.get(server)
129+
end
130+
131+
context 'when a connection cannot be checked out' do
132+
133+
before do
134+
allow(pool).to receive(:checkout).and_return(nil)
135+
pool.with_connection { |c| c }
136+
end
137+
138+
let(:queue) do
139+
pool.send(:queue).queue
140+
end
141+
142+
it 'does not add the connection to the pool' do
143+
expect(queue.size).to eq(1)
144+
end
145+
end
146+
end
120147
end

0 commit comments

Comments
 (0)