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

Query to mongodb stuck if the cluster primary lost network (using PyMongo)

    • Type: Icon: Bug Bug
    • Resolution: Gone away
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: 2.9.2, 3.12.2
    • Component/s: Cluster Mgmt
    • None

      Hello,

      I have a problem regarding mongo. Here is my setup:

      • 3 mongod with replica set on 3 different virtual machine
      • 1 mongo-configsvr on each of the 3 previous VM
      • 1 mongos on the client VM to route to the 3 mongod
      • A soft developed in Python (with PyMongo)

      Now, my problem. I'm developing a software that request a lot mongo. The problem appeared when my primary mongod VM lost network. At this time, the request that was last sent was stuck.
      By stuck I mean that the request wont work, but will not raise any "AutoReconnect" to let me do the request again so it can route to the new primary.
      The request is totally stucked, it will raise an error after 15 minutes OR if the network goes up again on the previous primary.

      I wrote a script to explain the problem:
      ```
      #!/usr/bin/python

      1. coding: utf-8

      import sys
      import threading
      import time
      from pymongo import MongoClient

      def main():

      mongo_client = MongoClient()
      db = mongo_client.test
      collection = db['test']
      collection.drop()
      collection = db['test']
      print u'Connected; lets go !'
      while True:
      t0 = time.time()
      collection.insert({'time': time.time()})
      print u'Wait [%03.6f] | There is %s items in test collection' % ((time.time() - t0), collection.count())
      print u'---------------------------------------------------------------'
      time.sleep(1)

      main()
      ```

      As you can see in the code, I do one request per second. So I let the script run, and then I remove the ethernet cable on the primary. The script stuck at the insert, the print will not be printed until the ethernet cable is put back or after 15 minutes.

      I can't believe that no one ever had the problem as losing network is not really hard. But I did not found anything using google.

      Hope you will have answers, thank you!

            Assignee:
            shane.harvey@mongodb.com Shane Harvey
            Reporter:
            t.clemenceau@shinken-solutions.com Thomas Clemenceau
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: