Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

Added retry mechanism for isCapped check #179

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions lib/mongo_ascoltatore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<that._maxRetry)
{
debug('checkCappedAndPoll -> 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');
Expand Down