svasva / meteor-publish-with-relations

Meteor.js SmartPackage to publish associated collections at once.
162 stars 30 forks source link

"Diamond" joins can cause bad deleting errors. #7

Open tmeasday opened 11 years ago

tmeasday commented 11 years ago

I've been meaning to create this for a while, the real cause is https://github.com/meteor/meteor/issues/944.

If you join onto the same record twice (ie. you end up "publishing" it twice), if you then delete it, Meteor basically blows up.

Reproduction: clone https://github.com/tmeasday/meteor-pwr-deleting-bug

This project makes a simple Posts -> Authors relation, and creates two posts with the same author. It then publishes them via PWR.

  1. Run the project
  2. Check Authors.find().count() is 1
  3. Run Authors.remove(Authors.findOne()._id) in the browser console.

You should see continuous errors of the form:

Exception in queued task: Error: Removed nonexistent document WM8ejhCgZqaTd275c
    at _.extend.removed (app/packages/livedata/livedata_server.js:181:17)
    at _.extend.removed (app/packages/livedata/livedata_server.js:322:10)
    at _.extend.removed (app/packages/livedata/livedata_server.js:990:19)
    at collection.find.observeChanges.removed (app/packages/publish-with-relations/publish_with_relations.coffee.js:18:20)
    at _.each.self._callbackMultiplexer.(anonymous function) (app/packages/mongo-livedata/mongo_driver.js:704:34)
    at Array.forEach (native)
    at Function._.each._.forEach (app/packages/underscore/underscore.js:79:11)
    at Object._.each.self._callbackMultiplexer.(anonymous function) [as removed] (app/packages/mongo-livedata/mongo_driver.js:701:9)
    at app/packages/minimongo/diff.js:40:18
    at Function._.each._.forEach (app/packages/underscore/underscore.js:87:24)

Appear in the logs. The server also kind of dies once this happens.

It's readily apparent when using PWR with presences (as presences are deleted all the time and you usually want to join onto them). See https://github.com/tmeasday/meteor-presence/issues/1

svasva commented 11 years ago

Oh, I see. Will check what I can do to sort this.

jonjamz commented 11 years ago

+1, I can't prove causality here because I'm not getting any specific error messages, but I did start getting server hangs once or twice a day since I switched to PWR.

It's only on my production server, and I can't seem to get my Meteor dev server to hang locally, for what it's worth.

jonjamz commented 11 years ago

Update: After a lot of testing, I tracked my problem to lines 7-13 of PWR.

dradovic commented 10 years ago

I'm running into the same problem. Is there are solution coming up? Do you know a work-around?

jonjamz commented 10 years ago

I worked on this for a while, couldn't find a workaround. Had to get off the package.

tmeasday commented 10 years ago

My workaround is to not use PWR for data that may be deleted, although @jonjamz thinks possibly he ran into problems even without deleting being involved, so that worries me.

I would probably steer clear of the package until further notice.

svasva commented 10 years ago

Hey guys, I'm sorry to be that late on reply, but I'm working on a big meteor project that doesn't involve this package (yet) so I didn't have time to look closer at this problem (yet). Not sure when I'll be able to, so forks/pull requests are appreciated for sure.

tmeasday commented 10 years ago

No worries Vitaly, I'm planning on looking at it too when I have a free moment. I know how you feel :)