Hello helpful meteor experts
we are having issues tracing down some reactivity problems after updating to meteor 3.0.3 . We did all the async migrations already on the last stable build still running meteor 2.10.0. The 3.0.3 build just updated meteor, all the packages and the node version. Building worked without problems and the build passed all tests on our staging environment and even ran for a couple days on production without us noticing any problems.
Then we realised that sometimes some Meteor methods are not working correctly anymore, but we can not reproduce it reliably. It only happens on production, not on any other environment (staging, develop,…), which run the same stack and build just with lower server resources and less traffic. Even on production there are stretches of up to hours where everything works, followed by hours where we can reproduce the problem.
The problematic methods run through without error and the connection receives the result
ddp message and also the added
and changed
messages of changes to subscribed documents, but the updated
message in the end is missing, which results in the message callback not being run. We are still using the old Meteor.call with callbacks. Those are async server only methods, so no stubs involved, which, if we understand the migration docs correctly, should still work fine.
We are making heavy use of subscriptions (which is probably unnecessary) on a lot of collections, but it is only one area of the webapp (a lower traffic area even) with a couple methods related to one subscription, where we are having issues. Some methods making changes to the same subscribed data, are always working completely fine, others are missing the updated
message. App and mongo server load seems fine and even doubling resources did not help. Rolling back to the 2.10.0 build removed the problem.
I know that it is probably hard to help without a way to reproduce the problem, but maybe someone has some advice of how to debug in this situation, without using production as a testing environment. If there is some DDP under the hood documentation, or instructions of how to add logging to meteor internals, that would be helpful as well.
From what I gathered from code comments in github, the updated
message is called to signify that all updates to the subscribed data changed by the method have been send out. However the added
and changed
messages are coming in (s. screenshots below), but the method is still stuck not sending the updated. I did not really get the details, how the system works though. Any ideas of what might be going wrong there are appreciated.
I added simplified example code of the subscription, a working method and another one that has this problem, in case that helps.
Unless we get a good hint, we will have to stay on meteor 2, change our method calls to async and get rid of all the unnecessary subscriptions and then try again.
Thanks for sticking with me and any potential advice
Simplified example code
The “docs.createCopy” method has the problem
The “docs.removeCopy” method always works
Meteor.publish("docs", function(docId) {
<checks and validations>
return Docs.find({ $or: [{ _id: docId }, { referenceList: docId }] });
});
Meteor.methods({
"docs.createCopy":async function (
docId: string,
): Promise<Doc> {
<checks and validations>
const doc = await Docs.findOneAsync({newDocRef: docId});
const newDoc = {referenceList: doc.referenceList ? [...doc.referenceList, docId] : [docId], ...moreProp}
const newDocId = (await Docs.insertAsync(newDoc))._id;
await Docs.updateAsync({ _id: docId }, { $set: { newDocRef: newDocId } });
return { ...newDoc, _id: newDocId }
},
"docs.removeCopy": async function (docId: string): Promise<void> {
<checks and validations>
const referencingDoc = await Docs.findOneAsync({newDocRef: docId});
await Docs.updateAsync(
{ _id: referencingDoc },
{ $unset: { newDocRef: 1 } },
);
await Docs.removeAsync({_id: docId });
},
})