From 98135c7df9e43367b19da711c84977e5e15c3cc5 Mon Sep 17 00:00:00 2001 From: vrde Date: Thu, 2 Feb 2017 20:59:17 +0100 Subject: [PATCH] Add hack to handle reconnection to changefeed --- bigchaindb/backend/mongodb/changefeed.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/bigchaindb/backend/mongodb/changefeed.py b/bigchaindb/backend/mongodb/changefeed.py index 0cf37943..8bdaca92 100644 --- a/bigchaindb/backend/mongodb/changefeed.py +++ b/bigchaindb/backend/mongodb/changefeed.py @@ -1,4 +1,3 @@ -import os import logging import time @@ -28,9 +27,13 @@ class MongoDBChangeFeed(ChangeFeed): while True: try: + # XXX: hack to force reconnection, + # the correct way to fix this is to manage errors + # for cursors.conn + self.connection.connection = None self.run_changefeed() break - except BackendError: + except (BackendError, pymongo.errors.ConnectionFailure): logger.exception('Error connecting to the database, retrying') time.sleep(1) @@ -48,13 +51,13 @@ class MongoDBChangeFeed(ChangeFeed): # last result was returned. ``TAILABLE_AWAIT`` will block for some # timeout after the last result was returned. If no result is received # in the meantime it will raise a StopIteration excetiption. - cursor = self.connection.conn.local.oplog.rs.find( - {'ns': namespace, 'ts': {'$gt': last_ts}}, - cursor_type=pymongo.CursorType.TAILABLE_AWAIT - ) + cursor = self.connection.run( + self.connection.query().local.oplog.rs.find( + {'ns': namespace, 'ts': {'$gt': last_ts}}, + cursor_type=pymongo.CursorType.TAILABLE_AWAIT + )) while cursor.alive: - print(os.getpid(), 'alive') try: record = cursor.next() except StopIteration: