iron-meteor / iron-router

A client and server side router designed specifically for Meteor.
MIT License
1.98k stars 413 forks source link

Subscription lost after a few minutes #1605

Closed gvlot closed 4 years ago

gvlot commented 4 years ago

Hello,

At this stage we are trying to upgrade from version 1.8.01 to version 1.10.2. Everything seems fine except this nasty bug. We have narrowed the problem down and it 'seems' that the issue is related to Iron:Route.

Our application is using Iron:route in combination with the Blaze templating engine. When we are using a route like this :

this.route('/:environmentId?/menu/:param1?/:param2?/:param3?/:param4?/:param5?/:param6?', { waitOn() { return Meteor.subscribe('menuContent', this.url, true); }, action() { const layout = Layouts.findOne(); console.log('Layout from subscription', layout); }, });

Initially when we interact with the application is fine. When the route is being triggerd the console output states: Layout from subscription [Document] So far so good.

Unfortunately after approximately five minutes triggering the same route (different value of the URL parameter) will lead to : Layout from subscription [Document] Layout from subscription undefined

As you would understand the result of the second subscription result is the problem. When a subscription after five minutes is being made, the publish function is not being triggered at all! If we subscribe outside the Iron route everything works also as expected.

The publication looks like this :

Meteor.publish('menuContent', function (url, isDesktop) { check(url, String); return Layouts.find({_id: 'JRfphYMtQuL97k9Pd'}) });

When we remove the URL parameter or assign the URL a static value the subscription stays interactive. In other words the application works as expected.

Do you have a clue how this is possible. I there a way to influence this behaviour ? Due to the time limit my best guess is that the GC kicks in .

Please advise as we are really in a desperate need of an upgrade.

gvlot commented 4 years ago

Hello !

I finally found the problem. After this amount of silence related to this thread … it had to be something Meteor implementation specific and indeed it was. Loosing subscription after five minutes was caused by the following code :

Meteor.setInterval(function() { let newDdpInfo = {}; _.each(Meteor.server.sessions, function(val, key) { newDdpInfo[key] = ddpInfo[key]; }); ddpInfo = newDdpInfo; }, 5*60000);

Removed this section and the subscriptions are still alive after five minutes … Great !! This answer might help somebody else …

Ticket can be closed