Skip to content

Commit

Permalink
Avoid 100% CPU in tailing during Mongo failover
Browse files Browse the repository at this point in the history
  • Loading branch information
glasser committed Dec 12, 2013
1 parent 7e02b83 commit 0e21a38
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/mongo-livedata/mongo_driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ MongoConnection.prototype.tail = function (cursorDescription, docCallback) {

var stopped = false;
var lastTS = undefined;
Meteor.defer(function () {
var loop = function () {
while (true) {
if (stopped)
return;
Expand Down Expand Up @@ -930,9 +930,16 @@ MongoConnection.prototype.tail = function (cursorDescription, docCallback) {
cursorDescription.collectionName,
newSelector,
cursorDescription.options));
// Mongo failover takes many seconds. Retry in a bit. (Without this
// setTimeout, we peg the CPU at 100% and never notice the actual
// failover.
Meteor.setTimeout(loop, 100);
break;
}
}
});
};

Meteor.defer(loop);

return {
stop: function () {
Expand Down

0 comments on commit 0e21a38

Please sign in to comment.