Skip to content

Commit d14d8e8

Browse files
committed
Don't call join() inside close()
1 parent 68c4a6e commit d14d8e8

File tree

6 files changed

+16
-16
lines changed

6 files changed

+16
-16
lines changed

pymongo/asynchronous/mongo_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,13 +1559,13 @@ async def close(self) -> None:
15591559
# Stop the periodic task thread and then send pending killCursor
15601560
# requests before closing the topology.
15611561
self._kill_cursors_executor.close()
1562+
if not _IS_SYNC:
1563+
await self._kill_cursors_executor.join()
15621564
await self._process_kill_cursors()
15631565
await self._topology.close()
15641566
if self._encrypter:
15651567
# TODO: PYTHON-1921 Encrypted MongoClients cannot be re-opened.
15661568
await self._encrypter.close()
1567-
if not _IS_SYNC:
1568-
await self._kill_cursors_executor.join()
15691569
self._closed = True
15701570

15711571
if not _IS_SYNC:

pymongo/asynchronous/monitor.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@ async def close(self) -> None:
111111
open() restarts the monitor after closing.
112112
"""
113113
self.gc_safe_close()
114-
if not _IS_SYNC:
115-
await self._executor.join()
116114

117115
async def join(self, timeout: Optional[int] = None) -> None:
118116
"""Wait for the monitor to stop."""
@@ -191,10 +189,12 @@ def gc_safe_close(self) -> None:
191189
self._rtt_monitor.gc_safe_close()
192190
self.cancel_check()
193191

192+
async def join(self, timeout: Optional[int] = None) -> None:
193+
await self._executor.join(timeout)
194+
await self._rtt_monitor.join()
195+
194196
async def close(self) -> None:
195197
self.gc_safe_close()
196-
if not _IS_SYNC:
197-
await self._executor.join()
198198
await self._rtt_monitor.close()
199199
# Increment the generation and maybe close the socket. If the executor
200200
# thread has the socket checked out, it will be closed when checked in.
@@ -464,8 +464,6 @@ async def close(self) -> None:
464464
self.gc_safe_close()
465465
# Increment the generation and maybe close the socket. If the executor
466466
# thread has the socket checked out, it will be closed when checked in.
467-
if not _IS_SYNC:
468-
await self._executor.join()
469467
await self._pool.reset()
470468

471469
async def add_sample(self, sample: float) -> None:

pymongo/asynchronous/topology.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,8 @@ async def _process_change(
520520
and self._description.topology_type not in SRV_POLLING_TOPOLOGIES
521521
):
522522
await self._srv_monitor.close()
523+
if not _IS_SYNC:
524+
await self._srv_monitor.join()
523525

524526
# Clear the pool from a failed heartbeat.
525527
if reset_pool:

pymongo/synchronous/mongo_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1553,13 +1553,13 @@ def close(self) -> None:
15531553
# Stop the periodic task thread and then send pending killCursor
15541554
# requests before closing the topology.
15551555
self._kill_cursors_executor.close()
1556+
if not _IS_SYNC:
1557+
self._kill_cursors_executor.join()
15561558
self._process_kill_cursors()
15571559
self._topology.close()
15581560
if self._encrypter:
15591561
# TODO: PYTHON-1921 Encrypted MongoClients cannot be re-opened.
15601562
self._encrypter.close()
1561-
if not _IS_SYNC:
1562-
self._kill_cursors_executor.join()
15631563
self._closed = True
15641564

15651565
if not _IS_SYNC:

pymongo/synchronous/monitor.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@ def close(self) -> None:
111111
open() restarts the monitor after closing.
112112
"""
113113
self.gc_safe_close()
114-
if not _IS_SYNC:
115-
self._executor.join()
116114

117115
def join(self, timeout: Optional[int] = None) -> None:
118116
"""Wait for the monitor to stop."""
@@ -191,10 +189,12 @@ def gc_safe_close(self) -> None:
191189
self._rtt_monitor.gc_safe_close()
192190
self.cancel_check()
193191

192+
def join(self, timeout: Optional[int] = None) -> None:
193+
self._executor.join(timeout)
194+
self._rtt_monitor.join()
195+
194196
def close(self) -> None:
195197
self.gc_safe_close()
196-
if not _IS_SYNC:
197-
self._executor.join()
198198
self._rtt_monitor.close()
199199
# Increment the generation and maybe close the socket. If the executor
200200
# thread has the socket checked out, it will be closed when checked in.
@@ -464,8 +464,6 @@ def close(self) -> None:
464464
self.gc_safe_close()
465465
# Increment the generation and maybe close the socket. If the executor
466466
# thread has the socket checked out, it will be closed when checked in.
467-
if not _IS_SYNC:
468-
self._executor.join()
469467
self._pool.reset()
470468

471469
def add_sample(self, sample: float) -> None:

pymongo/synchronous/topology.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,8 @@ def _process_change(
520520
and self._description.topology_type not in SRV_POLLING_TOPOLOGIES
521521
):
522522
self._srv_monitor.close()
523+
if not _IS_SYNC:
524+
self._srv_monitor.join()
523525

524526
# Clear the pool from a failed heartbeat.
525527
if reset_pool:

0 commit comments

Comments
 (0)