-
Type: Bug
-
Resolution: Done
-
Priority: Minor - P4
-
None
-
Affects Version/s: None
-
Component/s: None
-
Labels:None
-
Environment:MongoDB 2.4.6 ; pymongo==3.0.2-1-dce3f36
I observed some code infinite loop when using a tailable cursor on a capped collection.
The issue seems to be that after a find(...), cursor.alive is True even if the MongoDB isn't there, and continues being true after cursor.next() fails.
Also coll.find() continues to work even with no MongoDB.
This occurred in part of a data pipeline where we had a thread polling the tailable cursor and forwarding the data on to downstream consumers.
Repro looks like this (MongoTestServer is a fixtured MongoDB):
import gzip import bson from bson import json_util from bson import Binary import pymongo from pymongo import MongoClient import time import timeit from ahl.testing.mongo_server import MongoTestServer server = MongoTestServer() server.start() client = server.api coll = client.some_db.create_collection('some_coll', options={'capped': True}) coll.insert([{}, {}]) # while True: cursor = coll.find() assert cursor.next() while cursor.alive: print "cursor.alive" server.kill() # MongoDB will die at this point try: do_something_with_data(cursor.next()) except StopIteration: time.sleep(1) except Exception: # Catch any client exceptions... pass
This prints "cursor.alive" forever AFAICS.
Also this works without any MongoDB:
server.kill() while True: cursor = coll.find() assert cursor.alive