derbyjs / racer

Realtime model synchronization engine for Node.js
1.19k stars 118 forks source link

shareDoc.on() callback called multiple times #189

Closed ile closed 5 months ago

ile commented 10 years ago

I ran into a problem where this callback is called multiple times on the same operation: https://github.com/derbyjs/racer/blob/master/lib/Model/RemoteDoc.js#L22

I didn't find the code where these callbacks are removed. Are they actually removed somewhere?

If they are, there still seems to be some bug as it seems that they are not always removed. This same callback is called multiple times in some cases.

If needed, I can try to come up with a test case, but if you can spot the problem right away, that would also be good.

minicuper commented 10 years ago

Show us the way you make on call. Actually if you use on inside the components you should do it using scope.on (if you do it that way derby remove listeners itself), but if you use something like model.on .... you should remove listeners manually inside components destroy handler.

ile commented 10 years ago

I'm not calling it myself, it will get called on its own when I'm entering a route, subscribing to a doc. So, I'm not calling model.on myself.

The thing is that those callbacks get accumulated over time when I'm entering this one route (and subscribing) many times. They don't accumulate 100 % of the time, but just "sometimes".

Maybe I should create that test case.

minicuper commented 10 years ago

Yeah. Better show an example.

ile commented 10 years ago

Here: https://github.com/ilkkah/d-test3

It's modified from derby-examples/directory.

git clone git@github.com:ilkkah/d-test3.git
npm install
node server.js

Then open two browsers, add some people into the directory and then:

minicuper commented 10 years ago

Cloned your repo. See duplicates. Nate, it's a real bug. Data isn't duplicated in the model but it's duplicated in the view.

ile commented 10 years ago

Yes, only in the view, I should have been more clear about that. I assume the accumulated shareDoc.on callbacks put them there.

minicuper commented 10 years ago

Found one of the reasons - https://github.com/derbyjs/racer/blob/master/lib/Model/subscriptions.js#L243-L245. ShareDocs are never destroyed.

We need some more explanation from Nate about the 'race contition' sharejs bug.

minicuper commented 10 years ago

By the way, if you uncomment the line https://github.com/derbyjs/racer/blob/master/lib/Model/subscriptions.js#L245 the bug will disappear.

ile commented 10 years ago

Ok thanks. I'm not in a hurry, so I will be watching how this develops.

craigbeck commented 5 months ago

Thanks for your contributing your issue.

We have recently been actively updating the Derby and Racer packages, and both repos are now in Typescript and published with types on npm. As we have quite a few old issues open we have made the decision to close out of date issues.

If this issue still matters to you we encourage reproducing against the current versions of the repo and opening a new issue.