setInterval stops running when idle

Hello,

I have an application that checks users in. I am calling methods from the server every second through setInterval. After a period of idle time, these stop running, and my application does not work properly. What is the cause of this? Thank you.

That’s a pretty broad question with not a lot of information. Are you hosting your app on Meteor’s servers? I believe after a period of idle time your app will sleep to conserve resources and help keep the service free.

If that’s not it, I’d say start with the logs.

I suspected I did not give enough information.

It is on my own server.

The server log shows nothing; are you referencing another log?

If it does “sleep”, how should I awaken it or avoid the sleep? I wanted to know the common method for handling this.

Thanks for your reply.

You are calling methods from the server ? Meteor methods ?

No, my apologies for being confusing. The client is calling methods every second based on setInterval, and this ceases after about 30 minutes it seems.

Does the client stop calling the method or does the server stop responding? Can you share the relevant code? What happens if you manually call the method from the console in a client after the problem occurs? Just throwing questions out there to help you troubleshoot. What exploration have you done of the issue?

I believe the server stops responding, as it did not change the Session value in the console.

var setDateAndTimes = function () {
Meteor.call(‘getServerDate’, function(error, result) {
Session.set(‘serverDate’, result);
});
Meteor.setInterval( function() {
Meteor.call(‘getServerTime’, function(error, result) {
Session.set(‘serverTime’, result);
});
},1000);
Meteor.setInterval( function() {
Meteor.call(‘getServerTimeString’, function(error, result) {
Session.set(‘serverTimeString’, result);
});
},1000);
Meteor.setInterval( function() {
Meteor.call(‘createExpirationTime’, function(error, result) {
Session.set(‘expirationTime’, result);
console.log(Session.get(‘expirationTime’));
});
},1000);
}

Pardon my code if it is not the best, I am novice-intermediate level on most Meteor skills.

I am running this on my own server via the meteor command in the background. Does this make a difference regarding the performance of the server? Thanks.

All methods cease to function until I hit refresh on the browser. I noticed this because my submit, which inserts into a collection on the server, fails. Am I doing something wrong?

Are you getting any client errors? Sounds like maybe there’s a connection issue.

No, client functionality remains & I see no errors.

If I get your problem, the methods won’t be called on refresh as the browser will reset all intervals I guess. Just type

var timer = 0
setInterval(function() {
  console.log(timer)
  timer++
 }, 1000)

in your console and hit refresh. Using something like

Meteor.startup(function() {
  setDateAndTimes();
});

might fix it.

I am already doing it in Meteor.startup.

what you mean by fails? so you are submitting something to server from clients and it fails? what is the error message?
In that case it seems like “connection” issue, kinda as if something messed your client?

There is no error message. Clicking the submit button does not insert the data into the collection. It as if the application “freezes”. The cancel button works, and clicking submit throws validation errors, but when there are no errors, there is no feedback when clicking submit, nor any errors.

Same here, i have a dashboard witch updates the data with setInterval and after some time the interval stops for no reason, maybe some battery related problema with browsers?!