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

MongoClient.close does not stop its "pymongo_kill_cursors_thread"

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 3.8
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None

      Each MongoClient starts a thread to manage some of the client's resources (killing server cursors and maintaining the connection pool). This thread is named "pymongo_kill_cursors_thread" but it is only stopped after the client instance is garbage collected.

      This causes behavior described in https://github.com/mongodb/motor/pull/44. If we stopped the "pymongo_kill_cursors_thread" when a MongoClient is closed then the thread would be destroyed without the need for garbage collection. This also brings the kill cursors thread's lifetime more in line with the Topology's lifetime.

      I tested this theory using https://github.com/tjensen/motor-test-example and this pymongo branch and threads peeked around ~30 and remained stable for the entire nosetests run. Before the change I saw the number of threads climb to over 1300+.

      Note we'll need to be sure that the kill cursors thread is restarted if the client is reused after being closed.

            Assignee:
            shane.harvey@mongodb.com Shane Harvey
            Reporter:
            shane.harvey@mongodb.com Shane Harvey
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: