setInterval stops running when idle


#1

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.


#2

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.


#3

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.


#4

You are calling methods from the server ? Meteor methods ?


#5

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.


#6

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?


#7

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.


#8

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.


#9

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?


#10

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


#11

No, client functionality remains & I see no errors.


#12

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.


#13

I am already doing it in Meteor.startup.


#14

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?


#15

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.


#16

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?!