Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Website running JavaScript setInterval starts to fail after ~1day

I wish I could be more specific here, but unfortunately this might be hard. I basically hope this is some "well"-known timeout or setup issue.

We have a website running an (JS/html - ASP.net project) website overview on a screen at a factory. This screen has no keyboard so it should keep refreshing the page forever - years perhaps (though 1 week might be okay). (It is used by factory workers to see incoming transports etc.)

This all works perfectly; the site continuously updates itself and gets the new correct data. Then, sometimes, in the morning this "overview" screen has no data and the workers have to manually refresh the site using the simple refresh button or F5 - which fixes everything.

I have tried a few things trying to reproduce the error myself including:

  1. Cutting the internet connection and MANY other ways of making it timeout (breakpoints, stopping services etc.).
  2. Setting the refresh time of setInterval to 100ms and letting the site run 3-5 minutes. (normal timer is 1 minute)
  3. setInterval SHOULD run forever according to the internet searching I have done.
  4. Checked that "JavaScript frequency" has not been turned down in power saving settings.

No matter what; the site resumes correct function WITHOUT a refresh as soon as I plug in the internet cable or whatever again - I can't reproduce the error.

The website is dependent on a backend WCF service and project integration, but since the workers are fixing this with a simple refresh I am assuming this has not crashed.

EDIT: The browser I tried to reproduce the error in was IE/win7. I will ask about the factory tomorrow, but I am guessing IE/win? also.

Is setInterval in fact really infinite or is there something else wrong here?

All help much appreciated.

UPDATE: I came in this morning after leaving the website running in debug mode with a breakpoint in the catch clause of the site updating code. There was a 2 min. timeout error (busy server cleanup during the night likely) and THEN forever after that a null-reference error at this line:

var showHistory = (bool)Session.Contents["ShowHistory"];

I fixed it with a refresh like the workers. I am now thinking it may be a session timeout all though we keep pinging the server.. Of course my particular session timeout may have been caused by the breakpoint making it hang forever at the first timeout - still the behavior is the same as at the factory. I will make sure to update you guys with the final solution later.

UPDATE 2: Testing is ongoing.

UPDATE 3: The factory is IE 9, their test machine is IE 7 and my machine is IE 9. The error was seen on IE7 but NOT my IE9 after a weekends runtime. We tried turning off ajax cache during our critical data_binding code, but it did nothing. I tested for memory leaks and was able to create a decent leak IF I refresh 100 times per minute. I don't think it was the problem though and a refresh cleaned the memory used.

We will try the auto-refresh thing now.

like image 368
Martin Clemens Bloch Avatar asked Oct 06 '22 02:10

Martin Clemens Bloch


2 Answers

setInterval() should go on forever. But, it is possible that your script/page is leaking some sort of resource that eventually causes an error in your page script or internally to the browser.

If this is the case, you can probably eventually track down what sort of resource is leaking and fix the real problem, but even when doing that some browsers have their own issues with very long running processes.

It is probably worth watching resource usage to see if the browser memory usage goes up the longer the page runs. But, since an F5 fixes it, I would suggest that, as a safety measure, you just have the page reload itself every few hours. In most modern browsers a page reload, frees up all resources associated with the prior page run and gives you a clean slate from that standpoint.

Just doing this (which triggers every six hours):

setTimeout(function() {
    window.location.reload(true);
}, 6 * 1000 * 60 * 60);

will not only give you a clean start, but will also automatically cause your app to retrieve any server-side changes you might have made to the app every once in awhile so if you issue a bug fix, it will be automatically deployed within a few hours.

You could also use a meta refresh tag in your page.

like image 65
jfriend00 Avatar answered Oct 10 '22 04:10

jfriend00


I guess you are bitten by a recycle of the Application Pool. This will reset the server-side application and kill all sessions (at least if you use in-proc sessions, which is the default). This recycle could be scheduled to happen at 03:00, so that's why you don't see it in regular debug sessions, but only when you leave it running overnight.

You could check the existance of the Session within that webservice. If the Session is null, return a special value that triggers the page (your receiving javascript code) to do a full reload of the page, which will create a new Session. This way you do not have to wait for the scheduled page timeout to refill the page.

like image 22
Hans Kesting Avatar answered Oct 10 '22 04:10

Hans Kesting