Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

collection.observe() throws exception when handle._added is undefined #589

Closed
stiang opened this issue Jan 3, 2013 · 3 comments
Closed

collection.observe() throws exception when handle._added is undefined #589

stiang opened this issue Jan 3, 2013 · 3 comments

Comments

@stiang
Copy link

@stiang stiang commented Jan 3, 2013

I have the following code in server/publish.js:

Meteor.publish("counts-by-view", function (userId, randomery) {
  var self = this;

  Dummy.insert({name: "blabla"});

  updateViewCounts(self);

  var handle = Dummy.find().observe({
    changed: function (doc, idx) {
      updateViewCounts(self);
      self.flush();
    }
  });

  self.onStop(function () {
    handle.stop();
    self.flush();
  });

  self.flush();
});  

After upgrading from 0.5.0 to 0.5.2 I keep getting the following exception:

Internal exception while starting subscription 9456cbe6-93af-4cdd-8faa-edfbad9e9b34 TypeError: Property '_added' of object [object Object] is not a function
    at Object.Future.wait (/usr/local/meteor/lib/node_modules/fibers/future.js:322:15)
    at _.extend.runTask (app/packages/meteor/fiber_helpers.js:73:9)
    at _.extend._addObserveHandleAndSendInitialAdds (app/packages/mongo-livedata/mongo_driver.js:720:21)
    at _Mongo._observe (app/packages/mongo-livedata/mongo_driver.js:513:20)
    at Cursor.observe (app/packages/mongo-livedata/mongo_driver.js:338:22)
    at null.<anonymous> (app/server/publish.js:107:29)
    at sub._runHandler (app/packages/livedata/livedata_server.js:355:27)
    at _.extend._startSubscription (app/packages/livedata/livedata_server.js:381:9)
    at _.extend.protocol_handlers.sub (app/packages/livedata/livedata_server.js:224:12)
    at processNext (app/packages/livedata/livedata_server.js:188:43)
    - - - - -
    at _.extend._addObserveHandleAndSendInitialAdds (app/packages/mongo-livedata/mongo_driver.js:731:16)
    at Array.forEach (native)
    at Function._.each._.forEach (app/packages/underscore/underscore.js:79:11)
    at Object._.extend._addObserveHandleAndSendInitialAdds [as task] (app/packages/mongo-livedata/mongo_driver.js:730:9)
    at _.extend._run (app/packages/meteor/fiber_helpers.js:118:18)
    at _.extend._scheduleRun (app/packages/meteor/fiber_helpers.js:96:14)

This seems to be caused by _added being undefined in line 730 of meteor/packages/mongo-livedata/mongo_driver.js:

    handle._added(LocalCollection._deepcopy(doc),
                  self._ordered ? i : undefined);

Here is a dump of the "handle" variable in that method:

{ _liveResultsSet: 
   { _cursorDescription: { collectionName: 'dummy', selector: {}, options: {} },
     _mongoHandle: 
      { collection_queue: [],
        _liveResultsSets: [Object],
        db: [Object] },
     _ordered: true,
     _stopCallbacks: [ [Function], [Function], [Function] ],
     _synchronousCursor: 
      { _dbCursor: [Object],
        _synchronousNextObject: [Function],
        _synchronousCount: [Function],
        _visitedIds: [Object] },
     _results: 
      [ [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object],
        [Object] ],
     _pollsScheduledButNotStarted: 0,
     _addHandleTasksScheduledButNotPerformed: 0,
     _pendingWrites: [],
     _ensurePollIsScheduled: [Function],
     _taskQueue: 
      { _taskHandles: [],
        _runningOrRunScheduled: false,
        _currentTaskFiber: undefined },
     _observeHandles: { '15': [Object] },
     _callbackMultiplexer: 
      { added: [Function],
        changed: [Function],
        removed: [Function],
        moved: [Function] } },
  _added: undefined,
  _changed: [Function],
  _removed: undefined,
  _moved: undefined,
  _observeHandleId: 34 }

Am I doing something wrong here or is this a bug? Should _addObserveHandleAndSendInitialAdds check that _added is actually a function before trying to call it?

@glasser
Copy link
Member

@glasser glasser commented Jan 3, 2013

Good catch! I'm surprised nobody else has run into this, actually. I'll fix this and get the fix into 0.5.3.

@glasser
Copy link
Member

@glasser glasser commented Jan 3, 2013

Ah, I see, it only occurs if no added function is provided AND if cursor de-duping is applied.

BTW, you can work around this for now by just passing a no-op function for added to observe.

@glasser
Copy link
Member

@glasser glasser commented Jan 3, 2013

Fixed in 95974f8, not sure why the issue tracker integration didn't notice.

@glasser glasser closed this Jan 3, 2013
glasser added a commit that referenced this issue Jan 7, 2013
The cursor de-dup code introduced in Meteor 0.5.1 had a bug where a server-side
`observe` with no `added` callback would throw an error if the `observe` was
de-duped.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants