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

_RttMonitor causes ResourceWarning: unclosed <socket.socket fd=19, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('127.0.0.1', 56306), raddr=('127.0.0.1', 27017)>

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 3.11
    • Component/s: SDAM
    • None

      Noticed this ResourceWarning for an unclosed socket while running the tests. The ResourceWarning seem to randomly occur throughout the test suite. The unclosed socket is created by the _RttMonitor added in PYTHON-2123. Here's an example:

      $ python3 -X tracemalloc=25 setup.py test -s test.test_client
      ...
      test_lazy_connect_w0 (test.test_client.TestClient) ... /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/threading.py:233: ResourceWarning: unclosed <socket.socket fd=19, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('127.0.0.1', 56306), raddr=('127.0.0.1', 27017)>
        self._release_save = lock._release_save
      Object allocated at (most recent call last):
        File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/threading.py", lineno 890
          self._bootstrap_inner()
        File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/threading.py", lineno 932
          self.run()
        File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/threading.py", lineno 870
          self._target(*self._args, **self._kwargs)
        File "/Users/shane/git/mongo-python-driver/pymongo/periodic_executor.py", lineno 125
          if not self._target():
        File "/Users/shane/git/mongo-python-driver/pymongo/monitor.py", lineno 46
          monitor._run()
        File "/Users/shane/git/mongo-python-driver/pymongo/monitor.py", lineno 369
          rtt = self._ping()
        File "/Users/shane/git/mongo-python-driver/pymongo/monitor.py", lineno 379
          with self._pool.get_socket({}) as sock_info:
        File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/contextlib.py", lineno 113
          return next(self.gen)
        File "/Users/shane/git/mongo-python-driver/pymongo/pool.py", lineno 1225
          sock_info = self._get_socket(all_credentials)
        File "/Users/shane/git/mongo-python-driver/pymongo/pool.py", lineno 1275
          sock_info = self.connect(all_credentials)
        File "/Users/shane/git/mongo-python-driver/pymongo/pool.py", lineno 1180
          sock = _configured_socket(self.address, self.opts)
        File "/Users/shane/git/mongo-python-driver/pymongo/pool.py", lineno 988
          sock = _create_connection(address, options)
        File "/Users/shane/git/mongo-python-driver/pymongo/pool.py", lineno 950
          sock = socket.socket(
      /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/threading.py:233: ResourceWarning: unclosed <socket.socket fd=32, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('127.0.0.1', 56324), raddr=('127.0.0.1', 27017)>
        self._release_save = lock._release_save
      Object allocated at (most recent call last):
        File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/threading.py", lineno 890
          self._bootstrap_inner()
        File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/threading.py", lineno 932
          self.run()
        File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/threading.py", lineno 870
          self._target(*self._args, **self._kwargs)
        File "/Users/shane/git/mongo-python-driver/pymongo/periodic_executor.py", lineno 125
          if not self._target():
        File "/Users/shane/git/mongo-python-driver/pymongo/monitor.py", lineno 46
          monitor._run()
        File "/Users/shane/git/mongo-python-driver/pymongo/monitor.py", lineno 369
          rtt = self._ping()
        File "/Users/shane/git/mongo-python-driver/pymongo/monitor.py", lineno 379
          with self._pool.get_socket({}) as sock_info:
        File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/contextlib.py", lineno 113
          return next(self.gen)
        File "/Users/shane/git/mongo-python-driver/pymongo/pool.py", lineno 1225
          sock_info = self._get_socket(all_credentials)
        File "/Users/shane/git/mongo-python-driver/pymongo/pool.py", lineno 1275
          sock_info = self.connect(all_credentials)
        File "/Users/shane/git/mongo-python-driver/pymongo/pool.py", lineno 1180
          sock = _configured_socket(self.address, self.opts)
        File "/Users/shane/git/mongo-python-driver/pymongo/pool.py", lineno 988
          sock = _create_connection(address, options)
        File "/Users/shane/git/mongo-python-driver/pymongo/pool.py", lineno 950
          sock = socket.socket(
      ok
      test_list_database_names (test.test_client.TestClient) ... ok
      

      Here's an example from evergreen:

       [2020/07/30 01:13:31.552]   test_v2_db_aggregate_Aggregate_with_$listLocalSessions (test_crud_v2.TestSpec) ... /data/mci/1843e289f6ccf6880e33abf68b1877da/src/pymongo/periodic_executor.py:157: ResourceWarning: unclosed <socket.socket fd=11, family=AddressFamily.AF_INET, type=526337, proto=6, laddr=('127.0.0.1', 47305), raddr=('127.0.0.1', 27019)>
       [2020/07/30 01:13:31.552]   ref = weakref.ref(executor, _on_executor_deleted)
       [2020/07/30 01:13:31.573] ok (0.098s)
      

      https://evergreen.mongodb.com/task/mongo_python_driver_tests_python_version_rhel62_test_ssl__platform~rhel62_auth~noauth_ssl~nossl_python_version~3.6_coverage~coverage_test_latest_replica_set_c99254fe974110f6749028e8693b9c820349ff09_20_07_30_01_05_18

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

              Created:
              Updated: