Issue metadata
Sign in to add a comment
|
in code that was previously working, timers no longer go off
Reported by
wayne.se...@gmail.com,
Feb 1 2017
|
||||||||||||||||||||||
Issue description
UserAgent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:51.0) Gecko/20100101 Firefox/51.0
Steps to reproduce the problem:
execute code that sets a timer
What is the expected behavior?
the timer goes off and does something
What went wrong?
I am the developer for a private corporate site that allows contractors spread over a wide geographic area to interact with the corporate server. The work is task-based. The contractors are presented with a list of available tasks and after selecting one, download a file. After completing the task, they upload the results of their effort and payment is made.
The Job Queue, the list of available tasks, is the central screen of this operation. It lists the available jobs and the contractors select the one they want to work on. Due to competition between them, fast refresh of the job queue is critical, since the tasks are added to the list on an irregular schedule. There is a feeding frenzy when new jobs appear. So the contractors are allowed to set a timer with an interval as brief as 20 seconds, refreshing the screen on every timeout. At least that way they are on an equal footing, though it's still every man for himself.
This has been going on since 1999, though the traffic is much greater now.
Suddenly, the timer stopped working on Chrome. It appears to be because of the latest version. A contractor told me his auto refresh stopped working, and he had to do manual refresh to see the new jobs. In order to diagnose the problem, I checked the version of my own Chrome with About, so I could compare with his. To my horror, it did an automatic upgrade of Chrome without asking me. (That's a problem in itself; I usually allow a burn-in time for new versions, just because of crap like this. I'm not sure if I'll ever click on About again.) So now my timer refresh doesn't work either. I can set the interval as always, but there is no refresh---ever. The timer either doesn't start at all, or it doesn't operate correctly on completion.
Here is the code that operates the timer:
function setrefreshrate (the_form)
{
var m, seconds, nsecs;
// Decode what they entered
seconds = the_form.howoften.value;
if (seconds > '') {
nsecs = parseInt (seconds);
if (isNaN (nsecs) || (nsecs <= 0)) {
window.alert ('Please give a positive number of seconds, or leave empty for no refresh');
the_form.howoften.value = '';
the_form.howoften.focus ();
return (false);
}
if (nsecs < 20) {
window.alert ('The number of seconds cannot be less than 20');
the_form.howoften.value = '20';
seconds = '20';
}
}
the_form.howoften.blur ();
// Set the cookie to what they entered (or what we modified it to)
setcookie (seconds);
// Stop the old timer
if (oldtimerid != null) {
clearTimeout (oldtimerid);
oldtimerid = null;
}
// Start the new timer going
if (seconds == '') window.alert ('Page will not be automatically refreshed');
else {
m = 'Page will be refreshed every ' + seconds + ' seconds';
window.alert (m);
startrefreshtimer (the_form);
}
// Don't really do a submit
return (false)
}
function startrefreshtimer (the_form)
{
var cookies, i, j, seconds;
cookies = document.cookie;
i = cookies.indexOf (cookie_name);
if (i >= 0) {
j = cookies.indexOf (';', i);
if (j < 0) j = cookies.length;
seconds = cookies.substring (i + cookie_name.length, j);
the_form.howoften.value = seconds;
if (seconds > '')
if (parseInt (seconds) < 20) {
the_form.howoften.value = '20';
}
if (seconds > '') {
setcookie (seconds);
oldtimerid = setTimeout ('window.location.reload ()', parseInt (seconds) * 1000);
}
}
}
Slightly complicated setting up the timer, but the actual refresh isn't.
Again, was working fine and then minutes later, after the upgrade(?!), stone dead.
I single stepped through all this stuff with the debugger. No errors reported, all values looked correct (such as seconds). Whatever happened (or didn't happen) was apparently in the library routine setTimeout.
The contractors depend on the timer. If this isn't resolved quickly, they will go to firefox and forget chrome ever existed. And firefox does not have this problem, another indication my code is not to blame.
Did this work before? Yes not sure, "about" foolishly did an automatic upgrade when I tried to determine my version; i didn't get a chance to note the old one
Chrome version: Version 56.0.2924.76 (64-bit) Channel: n/a
OS Version: OS X 10.10
Flash Version: Shockwave Flash 24.0 r0
The automatic upgrade in "about" is another unrelated problem. I want to decide for myself when to upgrade. Because of problems like the timer failure.
,
Feb 2 2017
,
Feb 7 2017
Could you provide a minimized test case, more specific reproduction steps or perhaps a demo site? Is the tab ever backgrounded before the problem is seen?
,
Feb 7 2017
I will create a stripped down version of the HTML and the JS, removing all parts related to the application, leaving nothing but the form to specify the timer seconds and the "this display was generated at <timestamp>" that easily shows whether the timer is working or not. As far as the background thing: you have to be in foreground to SET the timer. I waited long enough to determine that it didn't go off, then I clicked on another tab for at least the timer interval. Then I came back to the timed screen. The timer never regenerated the screen at any point, just as it hasn't since installing the new chrome version.
,
Feb 7 2017
Okay, it doesn't appear to be the timer itself after all. After hard-coding twenty seconds and removing the form and anything else having to do with changing the interval, the screen gen time updates as it should. I will look at other parts of the code.
,
Feb 10 2017
The problem appears to be the code that changes the cookie containing the timer interval. This code dismisses the submit and accesses the cookie array in the browser directly, rather than submitting the form and letting the server update the cookie when regenerating the screen.
function setcookie (seconds)
{
nowdate = new Date ();
nowdate.setTime (nowdate.getTime () + 1000*3600*24*365);
now_year = nowdate.getYear ();
now_month = nowdate.getMonth ();
now_date = nowdate.getDate ();
now_day = nowdate.getDay ();
if (now_year < 100) now_year += 1900;
now_month = new Array ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec')[now_month];
if (now_date > 9) now_date = now_date.toString ();
else now_date = '0' + now_date.toString ();
now_day = new Array ('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat')[now_day];
document.cookie = cookie_name + seconds + '; path=/; expires=' + now_day + ', ' + now_date + '-' + now_month + '-' + now_year.toString () + ' 00:00:00 GMT';
}
I seem to have missed uploading this function earlier. Apparently there is something about this that the new version of chrome doesn't like, despite having no problem with it for many years. My guess is that the cookie doesn't get set, it's value is still blank, so the timer never gets started at all, having a blank interval.
I have rewritten the code to go ahead and do the submit, causing the processing module on the server to regenerate the cookie the normal way, through the data stream.
The screen updates now work as they did before. The only cost is a refresh up front, then the timer takes over.
As far as I am concerned, the issue is resolved. I will make a different complaint in the pertinent place regarding the automatic update of chrome without asking for permission.
It is up to you whether you pursue this or not. You might look at it. If the code above is considered valid javascript, then somebody else might have a problem doing it.
Otherwise, feel free to delete it.
,
Aug 7 2017
|
|||||||||||||||||||||||
►
Sign in to add a comment |
|||||||||||||||||||||||
Comment 1 by wayne.se...@gmail.com
, Feb 2 2017