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.

collection.insert() is not updating the redis subscription (no event "i" received by subscription manager)

See original GitHub issue

Meteor version: 1.6.1 Redis Oplog version: 1.2.7 Mongo DB version: 3.4.10 Redis version: 4.0.8

Problem: Inserting a new record in a collection does not update the subscription

Representative code: Notifications.insert(data, { namespace: 'userId::' + userId });

But updating the records work. With debug on, I can see that the subscription manager has no event “i” when inserting records.

I20180328-08:00:34.303(8)? [1522195234303] - [RedisSubscriptionManager] Subscribing to channel: userId::ccCN3JoGPSiWYyTf8::notifications
I20180328-08:00:55.231(8)? [1522195255231] - [RedisSubscriptionManager] Received event: "u" to "userId::ccCN3JoGPSiWYyTf8::notifications"

As of now, my simple remedy is to immediately update the record after inserting it so that it will update the subscription.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
nathan-muircommented, Apr 12, 2018

@rj-david had a quick look at your repo.

The issue is related to aldeed:collection2 / aldeed:collection2-core interacting with cultofcoders:redis-oplog


TLDR quickfix put aldeed:collection2 at the TOP of your .meteor/packages (above redis-oplog).

OR, slightly more robust:

Notifications.configureRedisOplog({
  mutation(options, {event, selector, modifier, doc}) { 
     if (event === 'i' && doc.userId != null) {
         options.namespace = `userId::${doc.userId}`
     } else if ((event === 'u' || event === 'r') && selector.userId != null) {
         options.namespace = `userId::${selector.userId}`  
     }
  }
 cursor(options, selector) {
   if (selector.userId != null) {
      options.namespace = `userId::${selector.userId}`
   }
 }
})

Explanation

aldeed:collection2 does not pass options from Collection.insert(doc, options) down to the _overriden.insert

So when you perform Notifications.insert(doc, {namespace: 'userId::' + userId}) the namespace is not actually reaching redis-oplog.

Note, that redis-oplog doesn’t pass the options down either so the easy solution (putting aldeed:collection2 first) means that you can’t pass options to collection2 like Collection.insert(doc, {validate: false})

So probably better to go with .configureRedisOplog on the collection…

1reaction
theodorDiaconucommented, Apr 3, 2018

Thank you @rj-david I will book this week time to sweep all the bugs from it!

Read more comments on GitHub >

github_iconTop Results From Across the Web

GraphQL subscriptions with Redis Pub Sub
The package introduced there uses an in-memory event system to re-run subscriptions, so there is no way to share subscriptions and publishes ...
Read more >
Error message while `yum update' "This system is registered ...
Any yum (update/install) command returns "This system is registered to Red Hat Subscription Management, but is not receiving updates.
Read more >
Redis keyspace notifications
Keyspace notifications allow clients to subscribe to Pub/Sub channels in order to receive events affecting the Redis data set in some way.
Read more >
How to configure Azure Cache for Redis | Microsoft Learn
Understand the default Redis configuration for Azure Cache for Redis and learn ... Select Events to add event subscriptions to your cache.
Read more >
Pub/Sub | Redis
Aside from data storage, Redis can be used as a Publisher/Subscriber platform. ... is put into subscriber mode and no commands can be...
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