Skip to content

Commit 84c5bb5

Browse files
authored
RUBY-1885 Remove wait argument on client/cluster/etc. close/disconnect methods (#1526)
* RUBY-1885 Remove wait argument on client/cluster/etc. close/disconnect methods * Fix the test suite * wait=true behavior is gone
1 parent 92b8b39 commit 84c5bb5

27 files changed

+51
-169
lines changed

lib/mongo/client.rb

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -669,17 +669,11 @@ def write_concern
669669

670670
# Close all connections.
671671
#
672-
# @example Disconnect the client.
673-
# client.close
674-
#
675-
# @param [ Boolean ] wait Whether to wait for background threads to
676-
# finish running.
677-
#
678672
# @return [ true ] Always true.
679673
#
680674
# @since 2.1.0
681-
def close(wait=false)
682-
@cluster.disconnect!(wait)
675+
def close
676+
@cluster.disconnect!
683677
true
684678
end
685679

lib/mongo/cluster.rb

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -422,22 +422,20 @@ def self.finalize(pools, periodic_executor, session_pool)
422422
end
423423
end
424424

425-
# Close the cluster and disconnect all servers.
425+
# Closes the cluster.
426426
#
427427
# @note Applications should call Client#close to disconnect from
428428
# the cluster rather than calling this method. This method is for
429429
# internal driver use only.
430430
#
431-
# @example Disconnect the cluster's servers.
432-
# cluster.disconnect!
433-
#
434-
# @param [ Boolean ] wait Whether to wait for background threads to
435-
# finish running.
431+
# Disconnects all servers in the cluster, publishing appropriate SDAM
432+
# events in the process. Stops SRV monitoring if it is active.
433+
# Marks the cluster disconnected.
436434
#
437435
# @return [ true ] Always true.
438436
#
439437
# @since 2.1.0
440-
def disconnect!(wait=false)
438+
def disconnect!
441439
unless @connecting || @connected
442440
return true
443441
end
@@ -452,7 +450,7 @@ def disconnect!(wait=false)
452450
end
453451
@servers.each do |server|
454452
if server.connected?
455-
server.disconnect!(wait)
453+
server.disconnect!
456454
publish_sdam_event(
457455
Monitoring::SERVER_CLOSED,
458456
Monitoring::Event::ServerClosed.new(server.address, topology)

lib/mongo/server.rb

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -219,41 +219,35 @@ def context
219219
# @deprecated No longer necessary with Server Selection specification.
220220
def connectable?; end
221221

222-
# Disconnect the server from the connection.
222+
# Disconnect the driver from this server.
223223
#
224-
# @example Disconnect the server.
225-
# server.disconnect!
224+
# Disconnects all idle connections to this server in its connection pool,
225+
# if any exist. Stops the populator of the connection pool, if it is
226+
# running. Does not immediately close connections which are presently
227+
# checked out (i.e. in use) - such connections will be closed when they
228+
# are returned to their respective connection pools. Stop the server's
229+
# background monitor.
226230
#
227-
# @param [ Boolean ] wait Whether to wait for background threads to
228-
# finish running.
229-
#
230-
# @return [ true ] Always true with no exception.
231+
# @return [ true ] Always true.
231232
#
232233
# @since 2.0.0
233-
def disconnect!(wait=false)
234+
def disconnect!
234235
if monitor
235236
monitor.stop!
236237
end
237238
_pool = @pool_lock.synchronize do
238239
@pool
239240
end
240241
if _pool
241-
if wait
242-
_pool.close(wait: wait)
243-
# Need to clear @pool as otherwise the old pool will continue to be
244-
# used if this server is reconnected in the future.
245-
@pool = nil
246-
else
247-
# For backwards compatibility we disconnect/clear the pool rather
248-
# than close it here. We also stop the populator which allows the
249-
# the pool to continue providing connections but stops it from
250-
# connecting in background on clients/servers that are in fact
251-
# intended to be closed and no longer used.
252-
begin
253-
_pool.disconnect!(stop_populator: true)
254-
rescue Error::PoolClosedError
255-
# If the pool was already closed, we don't need to do anything here.
256-
end
242+
# For backwards compatibility we disconnect/clear the pool rather
243+
# than close it here. We also stop the populator which allows the
244+
# the pool to continue providing connections but stops it from
245+
# connecting in background on clients/servers that are in fact
246+
# intended to be closed and no longer used.
247+
begin
248+
_pool.disconnect!(stop_populator: true)
249+
rescue Error::PoolClosedError
250+
# If the pool was already closed, we don't need to do anything here.
257251
end
258252
end
259253
@connected = false

lib/mongo/server/connection_pool.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -485,10 +485,8 @@ def clear(options = nil)
485485
#
486486
# @option options [ true | false ] :force Also close all checked out
487487
# connections.
488-
# @option options [ true | false ] :wait Wait for background threads to
489-
# exit before returning. Added in 2.10.0.
490488
#
491-
# @return [ true ] true.
489+
# @return [ true ] Always true.
492490
#
493491
# @since 2.9.0
494492
def close(options = nil)

spec/integration/change_stream_examples_spec.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@
2222
inventory.drop
2323
end
2424

25-
after do
26-
client.close(true)
27-
end
28-
2925
context 'example 1 - basic watching'do
3026

3127
it 'returns a change after an insertion' do

spec/integration/connection_pool_populator_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@
281281

282282
fork do
283283
# follow forking guidance
284-
client.close(true)
284+
client.close
285285
client.reconnect
286286
# let pool populate
287287
sleep 2

spec/integration/retryable_writes_errors_spec.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@
1818
authorized_client.with(retry_writes: true)
1919
end
2020

21-
after do
22-
client.close(true)
23-
end
24-
2521
context 'when a retryable write is attempted' do
2622
it 'raises an actionable error message' do
2723
expect {

spec/integration/sdam_events_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
client.database.command(ismaster: 1)
1414
expect(subscriber.events).to be_empty
1515

16-
client.close(true)
16+
client.close
1717

1818
expect(subscriber.events).not_to be_empty
1919
event = subscriber.first_event('server_closed_event')
@@ -31,7 +31,7 @@
3131
client.database.command(ismaster: 1)
3232
expect(subscriber.events).to be_empty
3333

34-
client.close(true)
34+
client.close
3535

3636
expect(subscriber.events).not_to be_empty
3737
event = subscriber.first_event('topology_closed_event')

spec/integration/server_selector_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
context 'there is a known primary' do
4040
before do
4141
client.cluster.next_primary
42-
client.close(true)
42+
client.close
4343
expect(client.cluster.connected?).to be false
4444
end
4545

@@ -51,7 +51,7 @@
5151
context 'there is no known primary' do
5252
before do
5353
primary_server = client.cluster.next_primary
54-
client.close(true)
54+
client.close
5555
expect(client.cluster.connected?).to be false
5656
primary_server.unknown!
5757
end

spec/mongo/auth/scram/negotiation_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
roles: ['root'],
2828
mechanisms: server_user_auth_mechanisms,
2929
)
30-
client.close(true)
30+
client.close
3131
end
3232
end
3333

0 commit comments

Comments
 (0)