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

High rate of connection creation leads to TCP errors

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 3.2
    • Component/s: Connection Mgmt
    • None
    • Environment:
      Windows Server 2012

      We observed several times the situation when one of the client was not able to acquire the connection because of the following error

      File "D:\app\python\lib\site-packages\pymongo\collection.py", line 2230, in update 
      with self._socket_for_writes() as sock_info: 
      File "D:\app\python\lib\contextlib.py", line 17, in _enter_ 
      return self.gen.next() 
      File "D:\app\python\lib\site-packages\pymongo\mongo_client.py", line 714, in _get_socket 
      with server.get_socket(self.__all_credentials) as sock_info: 
      File "D:\app\python\lib\contextlib.py", line 17, in _enter_ 
      return self.gen.next() 
      File "D:\app\python\lib\site-packages\pymongo\server.py", line 152, in get_socket 
      with self.pool.get_socket(all_credentials, checkout) as sock_info: 
      File "D:\app\python\lib\contextlib.py", line 17, in _enter_ 
      return self.gen.next() 
      File "D:\app\python\lib\site-packages\pymongo\pool.py", line 536, in get_socket 
      sock_info = self._get_socket_no_auth() 
      File "D:\app\python\lib\site-packages\pymongo\pool.py", line 570, in _get_socket_no_auth 
      sock_info, from_pool = self.connect(), False 
      File "D:\app\python\lib\site-packages\pymongo\pool.py", line 509, in connect 
      _raise_connection_failure(self.address, error) 
      File "D:\app\python\lib\site-packages\pymongo\pool.py", line 64, in _raise_connection_failure 
      raise AutoReconnect(msg) 
      AutoReconnect: 172.17.26.16:27017 Errno 10048 Only one usage of each socket address (protocol/network address/port) is normally permitted 
      

      In the windows system event log we had this record:

      TCP/IP failed to establish an outgoing connection because the selected local endpoint was recently used to connect to the same remote endpoint. This error typically occurs when outgoing connections are opened and closed at a high rate, causing all available local ports to be used and forcing TCP/IP to reuse a local port for an outgoing connection. To minimize the risk of data corruption, the TCP/IP standard requires a minimum time period to elapse between successive connections from a given local endpoint to a given remote endpoint.
      

      Indeed at this time we observed the high rate of the connections initialization, but
      we know that there were more then 8k of free TCP ports at that time, so the pool was not exhausted.
      However after we increased the TCP dynamic port range to the maximum the issue has gone.

      Could you please advice what could be the root-cause of such behavior and what are your recommendations to avoid that in future? I have a bad feeling that in some time it might happen again.

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

              Created:
              Updated:
              Resolved: