title: mongodb IndexError: pop from an empty deque
body: <p>I'm running a <code>pymongo</code> client and repeatedly getting this error. what does this mean and how can i prevent this?</p>
  <pre><code>Traceback (most recent call last):
    File &quot;/home/secondaryvm/.local/lib/python3.6/site-packages/pymongo/pool.py&quot;, line 1278, in _get_socket
      sock_info = self.sockets.popleft()
  IndexError: pop from an empty deque
  
  During handling of the above exception, another exception occurred:
  
  Traceback (most recent call last):
    File &quot;/home/secondaryvm/.local/lib/python3.6/site-packages/pymongo/pool.py&quot;, line 694, in command
      exhaust_allowed=exhaust_allowed)
    File &quot;/home/secondaryvm/.local/lib/python3.6/site-packages/pymongo/network.py&quot;, line 150, in command
      reply = receive_message(sock_info, request_id)
    File &quot;/home/secondaryvm/.local/lib/python3.6/site-packages/pymongo/network.py&quot;, line 195, in receive_message
      _receive_data_on_socket(sock_info, 16, deadline))
    File &quot;/home/secondaryvm/.local/lib/python3.6/site-packages/pymongo/network.py&quot;, line 286, in _receive_data_on_socket
      chunk_length = sock_info.sock.recv_into(mv[bytes_read:])
  ConnectionResetError: [Errno 104] Connection reset by peer
  
  During handling of the above exception, another exception occurred:
  
  Traceback (most recent call last):
    File &quot;mgclient.py&quot;, line 18, in &lt;module&gt;
      result=db.reviews.insert_one(business)
    File &quot;/home/secondaryvm/.local/lib/python3.6/site-packages/pymongo/collection.py&quot;, line 701, in insert_one
      session=session),
    File &quot;/home/secondaryvm/.local/lib/python3.6/site-packages/pymongo/collection.py&quot;, line 615, in _insert
      bypass_doc_val, session)
    File &quot;/home/secondaryvm/.local/lib/python3.6/site-packages/pymongo/collection.py&quot;, line 603, in _insert_one
      acknowledged, _insert_command, session)
    File &quot;/home/secondaryvm/.local/lib/python3.6/site-packages/pymongo/mongo_client.py&quot;, line 1498, in _retryable_write
      return self._retry_with_session(retryable, func, s, None)
    File &quot;/home/secondaryvm/.local/lib/python3.6/site-packages/pymongo/mongo_client.py&quot;, line 1384, in _retry_with_session
      return self._retry_internal(retryable, func, session, bulk)
    File &quot;/home/secondaryvm/.local/lib/python3.6/site-packages/pymongo/mongo_client.py&quot;, line 1408, in _retry_internal
      with self._get_socket(server, session) as sock_info:
    File &quot;/usr/lib/python3.6/contextlib.py&quot;, line 81, in __enter__
      return next(self.gen)
    File &quot;/home/secondaryvm/.local/lib/python3.6/site-packages/pymongo/mongo_client.py&quot;, line 1247, in _get_socket
      self.__all_credentials, checkout=exhaust) as sock_info:
    File &quot;/usr/lib/python3.6/contextlib.py&quot;, line 81, in __enter__
      return next(self.gen)
    File &quot;/home/secondaryvm/.local/lib/python3.6/site-packages/pymongo/pool.py&quot;, line 1231, in get_socket
      sock_info = self._get_socket(all_credentials)
    File &quot;/home/secondaryvm/.local/lib/python3.6/site-packages/pymongo/pool.py&quot;, line 1281, in _get_socket
      sock_info = self.connect(all_credentials)
    File &quot;/home/secondaryvm/.local/lib/python3.6/site-packages/pymongo/pool.py&quot;, line 1193, in connect
      sock_info.ismaster(all_credentials)
    File &quot;/home/secondaryvm/.local/lib/python3.6/site-packages/pymongo/pool.py&quot;, line 546, in ismaster
      return self._ismaster(None, None, None, all_credentials)
    File &quot;/home/secondaryvm/.local/lib/python3.6/site-packages/pymongo/pool.py&quot;, line 580, in _ismaster
      exhaust_allowed=awaitable)
    File &quot;/home/secondaryvm/.local/lib/python3.6/site-packages/pymongo/pool.py&quot;, line 699, in command
      self._raise_connection_failure(error)
    File &quot;/home/secondaryvm/.local/lib/python3.6/site-packages/pymongo/pool.py&quot;, line 891, in _raise_connection_failure
      _raise_connection_failure(self.address, error)
    File &quot;/home/secondaryvm/.local/lib/python3.6/site-packages/pymongo/pool.py&quot;, line 286, in _raise_connection_failure
      raise AutoReconnect(msg)
  pymongo.errors.AutoReconnect: 192.168.122.50:27017: [Errno 104] Connection reset by peer
  </code></pre>
  <p>I'm testing a setup where the responses from the server are delayed for long. But i want that client shouldn't get any type of timeout error.
  what changes to be made to prevent these either to server or client?</p>