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

Idle sockets never closed in Jython

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.2.1
    • Affects Version/s: 2.2
    • Component/s: None
    • None
    • Environment:
      Jython 2.5 and 2.7

      In Jython, the _del_ method of objects that inherit from 'object' is never called: http://bugs.jython.org/issue1057

      Starting in PyMongo 2.2, Pool inherits from object, and relies on its _del_ being called eventually in order to close its idle sockets, of which there are up to max_pool_size (default 10). So a loop like:

      from pymongo import Connection
      import threading
      
      def run():
          for i in range(200):
              c.test.test.find_one()
      
      for i in range(3):
          c = Connection()
          threads = [threading.Thread(target=run) for i in range(20)]
          for t in threads: t.start()
          for t in threads: t.join()
      

      ... will leave max_pool_size sockets open in each run. No amount of calling disconnect() or gc.collect() will close them. One would expect the JVM garbage collector to close the sockets some time after they are dereferenced, but in tests it does not. The solution is not to explicitly inherit Pool from object.

        1. testconn2.py
          0.4 kB
          A. Jesse Jiryu Davis

            Assignee:
            jesse@mongodb.com A. Jesse Jiryu Davis
            Reporter:
            jesse@mongodb.com A. Jesse Jiryu Davis
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: