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

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

    XMLWordPrintable

Details

    • Task
    • Status: Closed
    • Major - P3
    • Resolution: Fixed
    • None
    • 4.0
    • 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

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: