Skip to content

Commit 30667d1

Browse files
committed
PYTHON-2092 Avoid creating new connections during MongoClient.close
1 parent 5c02f8b commit 30667d1

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

doc/changelog.rst

+19
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
11
Changelog
22
=========
33

4+
Changes in Version 3.10.1
5+
-------------------------
6+
7+
Version 3.10.1 fixes the following issues discovered since the release of
8+
3.10.0:
9+
10+
- Fix a TypeError logged to stderr that could be triggered during server
11+
maintenance or during :meth:`pymongo.mongo_client.MongoClient.close`.
12+
- Avoid creating new connections during
13+
:meth:`pymongo.mongo_client.MongoClient.close`.
14+
15+
Issues Resolved
16+
...............
17+
18+
See the `PyMongo 3.10.1 release notes in JIRA`_ for the list of resolved issues
19+
in this release.
20+
21+
.. _PyMongo 3.10.1 release notes in JIRA: https://jira.mongodb.org/secure/ReleaseNote.jspa?projectId=10004&version=25039
22+
423
Changes in Version 3.10.0
524
-------------------------
625

pymongo/mongo_client.py

+11-7
Original file line numberDiff line numberDiff line change
@@ -1165,10 +1165,10 @@ def close(self):
11651165
session_ids = self._topology.pop_all_sessions()
11661166
if session_ids:
11671167
self._end_sessions(session_ids)
1168-
# Stop the periodic task thread and then run _process_periodic_tasks
1169-
# to send pending killCursor requests before closing the topology.
1168+
# Stop the periodic task thread and then send pending killCursor
1169+
# requests before closing the topology.
11701170
self._kill_cursors_executor.close()
1171-
self._process_periodic_tasks()
1171+
self._process_kill_cursors()
11721172
self._topology.close()
11731173
if self._encrypter:
11741174
# TODO: PYTHON-1921 Encrypted MongoClients cannot be re-opened.
@@ -1717,10 +1717,8 @@ def _kill_cursors(self, cursor_ids, address, topology, session):
17171717
duration, reply, 'killCursors', request_id,
17181718
tuple(address))
17191719

1720-
# This method is run periodically by a background thread.
1721-
def _process_periodic_tasks(self):
1722-
"""Process any pending kill cursors requests and
1723-
maintain connection pool parameters."""
1720+
def _process_kill_cursors(self):
1721+
"""Process any pending kill cursors requests."""
17241722
address_to_cursor_ids = defaultdict(list)
17251723

17261724
# Other threads or the GC may append to the queue concurrently.
@@ -1741,6 +1739,12 @@ def _process_periodic_tasks(self):
17411739
cursor_ids, address, topology, session=None)
17421740
except Exception:
17431741
helpers._handle_exception()
1742+
1743+
# This method is run periodically by a background thread.
1744+
def _process_periodic_tasks(self):
1745+
"""Process any pending kill cursors requests and
1746+
maintain connection pool parameters."""
1747+
self._process_kill_cursors()
17441748
try:
17451749
self._topology.update_pool()
17461750
except Exception:

0 commit comments

Comments
 (0)