diff --git a/packages/meteor/fiber_helpers.js b/packages/meteor/fiber_helpers.js index e1b0778c31..9d0ce4180d 100644 --- a/packages/meteor/fiber_helpers.js +++ b/packages/meteor/fiber_helpers.js @@ -52,6 +52,11 @@ Meteor._SynchronousQueue = function () { // that task. We use this to throw an error rather than deadlocking if the // user calls runTask from within a task on the same fiber. self._currentTaskFiber = undefined; + // This is true if we're currently draining. While we're draining, a further + // drain is a noop, to prevent infinite loops. "drain" is a heuristic type + // operation, that has a meaning like unto "what a naive person would expect + // when modifying a table from an observe" + self._draining = false; }; _.extend(Meteor._SynchronousQueue.prototype, { @@ -91,11 +96,15 @@ _.extend(Meteor._SynchronousQueue.prototype, { drain: function () { var self = this; + if (self._draining) + return; if (!self.safeToRunTask()) return; + self._draining = true; while (!_.isEmpty(self._taskHandles)) { self.flush(); } + self._draining = false; }, _scheduleRun: function () {