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

Network error causes leaked semaphore

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.6
    • Affects Version/s: 2.6
    • Component/s: None
    • None

      Bug in implementation of PYTHON-436 in unreleased version of PyMongo, code in current master branch.

      Consider:

      import time
      from pymongo.pool import Pool
      
      p = Pool(
          ('localhost', 27017), 1, None, None, False, False, wait_queue_timeout=100)
      
      p.start_request()
      
      # Get and close the request socket.
      request_sock_info = p.get_socket()
      request_sock_info.sock.close()
      p.maybe_return_socket(request_sock_info)
      
      # Pool won't check for closed sockets if they've been used in the last second.
      time.sleep(1.5)
      
      # Creates new socket, semaphore value still 0.
      request_sock_info_2 = p.get_socket()
      assert request_sock_info != request_sock_info_2
      p.maybe_return_socket(request_sock_info_2)
      p.end_request()
      

      Expected: Script completes normally.

      Actual: Script hangs 100 seconds, then raises "ConnectionFailure: Timed out waiting for socket from pool with max_size 1 and wait_queue_timeout 100".

      The semaphore is decremented if the request socket is broken, when it shouldn't be decremented.

      Note also that wait_time_seconds is supposed to be milliseconds but is actually seconds.

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

              Created:
              Updated:
              Resolved: