Permalink
Browse files

Fix use of cursor.observe at server-side startup.

A block that wasn't allowed to yield called _Mongo::_createSynchronousCursor,
which certainly can yield (it waits on a Future) but doesn't actually end up
needing to yield unless it is called during the initial connection to
Mongo... eg, during startup.

Fixes #507 (reported by paulreimer).
  • Loading branch information...
glasser committed Nov 24, 2012
1 parent 68db80f commit 0757e96e6d6a0ed22ecc1d015145baf7df742a06
Showing with 13 additions and 4 deletions.
  1. +13 −4 packages/mongo-livedata/mongo_driver.js
@@ -490,7 +490,7 @@ _Mongo.prototype._observe = function (cursorDescription, ordered, callbacks) {
// take place.
liveResultsSet = new LiveResultsSet(
cursorDescription,
- self._createSynchronousCursor(cursorDescription),
+ self,
ordered,
function () {
delete self._liveResultsSets[observeKey];
@@ -516,15 +516,19 @@ _Mongo.prototype._observe = function (cursorDescription, ordered, callbacks) {
return observeHandle;
};
-var LiveResultsSet = function (cursorDescription, synchronousCursor, ordered,
+var LiveResultsSet = function (cursorDescription, mongoHandle, ordered,
stopCallback) {
var self = this;
self._cursorDescription = cursorDescription;
- self._synchronousCursor = synchronousCursor;
+ self._mongoHandle = mongoHandle;
self._ordered = ordered;
self._stopCallbacks = [stopCallback];
+ // This constructor cannot yield, so we don't create the synchronousCursor yet
+ // (since that can yield).
+ self._synchronousCursor = null;
+
// previous results snapshot. on each poll cycle, diffs against
// results drives the callbacks.
self._results = ordered ? [] : {};
@@ -679,7 +683,12 @@ _.extend(LiveResultsSet.prototype, {
self._pendingWrites = [];
// Get the new query results. (These calls can yield.)
- self._synchronousCursor.rewind();
+ if (self._synchronousCursor) {
+ self._synchronousCursor.rewind();
+ } else {
+ self._synchronousCursor = self._mongoHandle._createSynchronousCursor(
+ self._cursorDescription);
+ }
var newResults = self._synchronousCursor.getRawObjects(self._ordered);
var oldResults = self._results;

0 comments on commit 0757e96

Please sign in to comment.