raix-push icon indicating copy to clipboard operation
raix-push copied to clipboard

Mass removal of tokens in Meteor 1.7

Open artpolikarpov opened this issue 7 years ago • 6 comments

This is urgent. Just found that this piece of raix:push-update method:

      // xxx: Hack
      // Clean up mech making sure tokens are uniq - android sometimes generate
      // new tokens resulting in duplicates
      var removed = Push.appCollection.remove({
        $and: [
          { _id: { $ne: doc._id } },
          { token: doc.token },     // Match token
          { appName: doc.appName }, // Match appName
          { token: { $exists: true } }  // Make sure token exists
        ]
      });

...is deleting all tokens from _raix_push_app_tokens collection some times!

artpolikarpov avatar Jul 20 '18 13:07 artpolikarpov

It happens when doc.token is undefined for some reason. I think we should change it to options.token.

artpolikarpov avatar Jul 21 '18 07:07 artpolikarpov

@artpolikarpov I think this method may be correct. When the message was sent were all the apps installed? If the app is not installed, I think the token is automatically removed on failed delivery, until the user opens the app and registers a new token.

da314pc avatar Aug 14 '18 04:08 da314pc

@da314pc If you carefully read the source, then you see that on failed delivery, tokens are nulled, not removed.

artpolikarpov avatar Aug 14 '18 07:08 artpolikarpov

I'll do some digging. were all your tokens removed?

da314pc avatar Aug 14 '18 07:08 da314pc

Not all but many. Thanks goodness I had a duplicate collection for them. In general, I warned.

artpolikarpov avatar Aug 14 '18 08:08 artpolikarpov

I can confirm that this is an issue. As @artpolikarpov stated, the tokens are being being cleared. When this function comes around, null isn't considered in the $and statement and therefore is considered the same as: var removed = Push.appCollection.remove({ $and: [ { _id: { $ne: doc._id } }, { appName: doc.appName }, // Match appName { token: { $exists: true } } // Make sure token exists ] });

This therefore removes ALL tokens that are valid.

The workaround we have is:

if(doc.token){ var removed = Push.appCollection.remove({ $and: [ { _id: { $ne: doc._id } }, { token: doc.token }, // Match token { appName: doc.appName }, // Match appName { token: { $exists: true } } // Make sure token exists ] }); }

CyberCyclone avatar Sep 03 '18 06:09 CyberCyclone