From 59e59d58df50fb4dae36e4cd32a7c1719180f8df Mon Sep 17 00:00:00 2001 From: dushyantbangal Date: Fri, 18 Aug 2017 15:44:02 +0530 Subject: [PATCH] Added retry mechanism for isCapped check --- lib/mongo_ascoltatore.js | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/lib/mongo_ascoltatore.js b/lib/mongo_ascoltatore.js index 2315dbc..0c8562f 100644 --- a/lib/mongo_ascoltatore.js +++ b/lib/mongo_ascoltatore.js @@ -226,15 +226,30 @@ MongoAscoltatore.prototype._handleCursorClosed = function (latest) { * @param latest * @private */ -MongoAscoltatore.prototype._checkCappedAndPoll = function(latest) { +MongoAscoltatore.prototype._checkCappedAndPoll = function(latest, retryCount) { debug('checkCappedAndPoll'); var that = this; this.collection.isCapped(function(err, isCapped) { - if (err) { - debug('checkCappedAndPoll -> Cannot stat isCapped. Give up'); - that.emit('error', new Error('Cannot stat if collection is capped or not')); - that._handlingCursorFailure = false; - return; + if (err) + { + if(!retryCount) + retryCount=0; + if(retryCount Cannot stat isCapped. Retry'); + retryCount++ + setTimeout(function(){ + that._checkCappedAndPoll(latest, retryCount); + },100*retryCount) + + return; + }else{ + debug('checkCappedAndPoll -> Cannot stat isCapped. Give up'); + + that.emit('error', new Error('Cannot stat if collection is capped or not')); + that._handlingCursorFailure = false; + return; + } } if (!isCapped) { debug('checkCappedAndPoll -> Collection is not capped. Give up');