question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ServerSide Autorun Triggers 'Removed' Events Bug

See original GitHub issue

We 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

  1. Run meteor npm i
  2. Start the server with npm start
  3. Load localhost:3000
  4. Make sure redis oplog is enabled
  5. Click to add 100 users (might have to do this more than once)
  6. 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:closed
  • Created 5 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
etypcommented, Apr 23, 2018
0reactions
ramezraflacommented, Jan 27, 2019

Can we close?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Player Events - Brightcove Player Documentation
The Brightcove Player runs on top of the HTML framework, which triggers the following Media Events. Here are some terms associated with events...
Read more >
How to resolve the non triggering issue of server-side events?
Non triggering issue of Server side events of Grid can be resolved by referring ej.webform.min.js script file and adding ScriptManager Control to the...
Read more >
Reporting Events - Dynamic Yield Knowledge Base
Remove from Cart events must always have the total value of the removed product. Value must be non-negative. SKU as in the feed....
Read more >
WMI Event Consumers: what are you missing? - Velociraptor
In short, a WMI event consumer is a method of subscribing to certain system events, then enabling an action of some sort. Common...
Read more >
How Can I Automatically Run a Script Any Time a File is ...
Hey, Scripting Guy! Is it possible to have a script automatically run any time a file is added to a specific folder?
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found