Uploaded image for project: 'Python Driver'
  1. Python Driver
  2. PYTHON-2463

Do not allow a MongoClient to be reused after it is closed

    • Type: Icon: Task Task
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 4.0
    • Affects Version/s: None
    • Component/s: None
    • None
    • Major Change

      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.

            Assignee:
            julius.park@mongodb.com Julius Park (Inactive)
            Reporter:
            shane.harvey@mongodb.com Shane Harvey
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: