ServerSide Autorun Triggers 'Removed' Events Bug
See original GitHub issueWe use serverside autoruns pretty heavily in our codebase. Upon adding a new user to our workspace model we sometimes see all the existing users get removed from the client side collection. This does not happen every time so that leads me to believe there is a race condition that is causing this. Looking at the ddp messages sent through websocket, I noticed that the server is actually sending ‘removed’ events down to the client. I was not able to reproduce this exactly in this simple repo but I think I was able to get at the core of the problem.
Here is a simple reproduction repo: https://github.com/hiveteams/redis-oplog-reproduction
Issue
When changes to the workspace document are made (ex: a new user being added to the list of workspace members), the redis oplog causes removed events to be propagated to the client resulting in users disappearing from the client collection.
Steps to reproduce
- Run
meteor npm i
- Start the server with
npm start
- Load localhost:3000
- Make sure redis oplog is enabled
- Click to add 100 users (might have to do this more than once)
- Notice that the users are not cleanly added, several ‘removed’ events are sent through ddp.
If you toggle to disable redis oplog and then try again you will notice that no ‘removed’ events are sent through ddp.
Workspace
{
"_id": "Mongo id",
"members": "List of user ids"
}
User
{
"_id": "Mongo id"
}
The Code
Basically just a publish where we depend on the results of the workspaces query to return the final set of users:
Meteor.publish('allUsers', function allUsersPub(enableRedisOplog) {
this.autorun(() => {
// listen to changes in the workspace document
const workspace = Workspaces.find().fetch()[0];
// optionally disable redis oplog
const options = {};
if (!enableRedisOplog) {
options.disableOplog = true;
}
// return users cursor
return Users.find({
_id: { $in: workspace.members }
}, options);
});
});
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (6 by maintainers)
Top GitHub Comments
Uses peerlibrary:server-autorun + peerlibrary:reactive-publish
Can we close?