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

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



    • Bug
    • Status: Closed
    • Unknown
    • Resolution: Gone away
    • 2.9.2, 3.12.2
    • None
    • Cluster Mgmt
    • None



      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:

      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 = 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'---------------------------------------------------------------'


      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!


        Issue Links



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