Details
-
Task
-
Status: Closed
-
Major - P3
-
Resolution: Fixed
-
None
-
None
-
None
-
Major Change
Description
A MongoClient instance can be re-used after being closed, for example this is valid:
client = MongoClient()
|
client.test.test.find_one()
|
client.close()
|
client.test.test.find_one()
|
This behavior is odd because closing a resource usually means it is no longer needed; a closed file descriptor does not magically reopen itself. No other MongoDB drivers that work this way as far as I know.
This automatic reopening behavior also leads to bugs and implementation complexity, especially while threading is involved. For example some related bugs are:
For more motivation, while implementing PYTHON-2462 I had to include special logic to circumvent the Pool paused state when the client is closed to avoid breaking the behavior of test.test_threads.TestThreads.test_client_disconnect. We should consider whether we want to remove that logic and instead raise an error on all operations after a client.close(). This would be a breaking change that could go in 4.0.
Attachments
Issue Links
- causes
-
PYTHON-2935 Test Failure - test_use_after_close
-
- Closed
-
- is related to
-
PYTHON-2938 Fix race condition caused by MongoClient._process_periodic_tasks(client)
-
- Closed
-
- related to
-
PYTHON-2462 Implement and test connection pool paused state
-
- Closed
-