Diggsey / meteor-reactive-publish

Enable server-side reactivity for Meteor.publish
MIT License
41 stars 5 forks source link

Package attempting to remove documents for no apparent reason. #7

Closed Scalahansolo closed 10 years ago

Scalahansolo commented 10 years ago

I just started using this package, and I was having a very strange issue. This is my reactive publish function.

Meteor.reactivePublish 'user_messages', (roomName) ->
        console.log "Publishing Messages"
        room = Rooms.find({room_name: roomName}, {fields: {_id: 1, 'active_users.maxMessages': 1, 'active_users.user'}, reactive: true}).fetch()
        activeUsers = room[0].active_users

        roomId = room[0]._id

        for user in activeUsers
            if user.user._id == @userId
                dl = user.maxMessages

        console.log "Message Count: " + dl
        return Messages.find({room: roomId, type: "user_message"}, {sort: {time: -1}, limit: dl, fields: {_id: 1, name: 1, message: 1, room: 1, time: 1, type: 1}})

And I am subscribing in my routes file like so, where the room name is set above

waitOn: ->
   Meteor.subscribe('user_messages', @params.room_name)

Now when I start input messages into my database, everything seemed to be working just fine until I hit a particular message count (In our case, the 27th message). Once I hit this somewhat random point, I would get the following error

Exception in queued task: Error: Removed nonexistent document ohwvDwsfa2pHL6wvM
I20140801-12:03:09.340(-6)?     at _.extend.removed (packages/livedata/livedata_server.js:194)
I20140801-12:03:09.340(-6)?     at _.extend.removed (packages/livedata/livedata_server.js:383)
I20140801-12:03:09.340(-6)?     at _.extend.removed (packages/livedata/livedata_server.js:1097)
I20140801-12:03:09.341(-6)?     at cursor.observeChanges.removed (packages/reactive-publish/lib/reactive-publish.coffee:93:8)
I20140801-12:03:09.341(-6)?     at packages/mongo-livedata/observe_multiplex.js:163
I20140801-12:03:09.341(-6)?     at Array.forEach (native)
I20140801-12:03:09.341(-6)?     at Function._.each._.forEach (packages/underscore/underscore.js:105)
I20140801-12:03:09.341(-6)?     at Object.task (packages/mongo-livedata/observe_multiplex.js:157)
I20140801-12:03:09.341(-6)?     at _.extend._run (packages/meteor/fiber_helpers.js:150)
I20140801-12:03:09.341(-6)?     at packages/meteor/fiber_helpers.js:128

No where in our code are we attempting to remove messages, so I was unsure why this was happening. So my quick and dirty fix was just comment out lines 91-93 and everything worked just as intended. So for now, I am just going to leave it this way, but I would obviously like to come a real solution and get this fixed properly.

EDIT: Currently we do not delete any messages from our database in a way that would effect this publish, so this quick fix works for now, but as previously said, we would like to figure out why it is breaking.

callmephilip commented 10 years ago

Same issue here. Looks like 'removed' cursor handler is invoked multiple times

scaljeri commented 10 years ago

+1 I've the same problem. It would be really nice if this could be fixed!