Last Comment Bug 758125 - Some timers in worker never fired
: Some timers in worker never fired
Status: RESOLVED FIXED
: testcase
Product: Core
Classification: Components
Component: DOM: Workers (show other bugs)
: Trunk
: x86 Linux
: -- normal with 1 vote (vote)
: mozilla17
Assigned To: Kyle Huey [:khuey] (Exited; not receiving bugmail, email if necessary)
:
:
Mentors:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2012-05-23 23:47 PDT by Rex
Modified: 2012-08-11 19:56 PDT (History)
5 users (show)
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Attachments
test case: worker (374 bytes, text/plain)
2012-07-27 09:11 PDT, Paul Rouget [:paul]
no flags Details
test case (use this) (737 bytes, text/html)
2012-07-27 09:12 PDT, Paul Rouget [:paul]
no flags Details
test case (use this) (793 bytes, text/html)
2012-07-27 09:13 PDT, Paul Rouget [:paul]
no flags Details
Patch (4.55 KB, patch)
2012-08-08 10:48 PDT, Kyle Huey [:khuey] (Exited; not receiving bugmail, email if necessary)
bent.mozilla: review+
Details | Diff | Splinter Review

Description Rex 2012-05-23 23:47:10 PDT
User Agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:12.0) Gecko/20100101 Firefox/12.0
Build ID: 20120423122624

Steps to reproduce:

Ubuntu 12.04
Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:12.0) Gecko/20100101 Firefox/12.0
browser.startup.homepage_override.buildID=20120423122624

MainUI.html
==============================
<html>
<head>
<script type="text/javascript">
    function AreaController(areaId) {
        var area = null;
        this.append = function(line) {
            if (area == null) {
                area = document.getElementById(areaId);
            }
            area.value += (line + "\n");
        };
        this.clear = function() {
            area.value = "";
        };
    }

    leftArea = new AreaController("leftText");

    worker = new Worker("WebWorker.js");
    worker.onmessage = function(event) {
        leftArea.append(event.data);
    }
</script>
</head>
<body>
	<textarea id="leftText" rows="30" cols="50" readonly="readonly"></textarea>
	<br />
	<input type="button" value="Clear" onClick="leftArea.clear()">
</body>
</html>


WebWorker.js
==============================
function sendLater(msg) {
    postMessage("");
    postMessage("Scheduling:" + new Date().getTime());

    setTimeout(function() {
        postMessage("Firing    :" + new Date().getTime());
        postMessage(msg);
    }, 1);

    postMessage("Scheduled :" + new Date().getTime());
}

setInterval(function() {
    sendLater("Interval  :" + new Date().getTime());
}, 3000);



Actual results:

In the test case worker will fire a repeat timer every 3 seconds. It sends a message back to main UI by scheduling and using another quick timer (1ms). Some 1ms timer would never fire.

I see output on main UI below. A 4 line block is a good case. A 2 line block means the 1ms has never fired. These results will appear in the first couple of minutes.

==============================
Scheduling:1337840998402
Scheduled :1337840998402
Firing    :1337840998403
Interval  :1337840998402

Scheduling:1337841001401
Scheduled :1337841001401
Firing    :1337841001402
Interval  :1337841001401

Scheduling:1337841004398
Scheduled :1337841004398

Scheduling:1337841007401
Scheduled :1337841007401
Firing    :1337841007402
Interval  :1337841007401

Scheduling:1337841010401
Scheduled :1337841010401
Firing    :1337841010403
Interval  :1337841010401

Scheduling:1337841013397
Scheduled :1337841013397

Scheduling:1337841016400
Scheduled :1337841016400

Scheduling:1337841019402
Scheduled :1337841019402
Firing    :1337841019403
Interval  :1337841019402



Expected results:

If every timer scheduled fires correctly, we should see all 4 line blocks.
Comment 1 Rex 2012-06-25 12:27:38 PDT
Verified that it is still happening in version 13.0.1.

Version info: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:13.0) Gecko/20100101 Firefox/13.0.1
Comment 2 Marcin Kulik 2012-07-20 02:55:41 PDT
Verified that it still happening in 14.0.1 on Ubuntu 12.04.
I had similar code that was using small timeout values, between 3-7 ms.
I tested it with several values and it seems the smaller the timeout value the more likely it will NOT be fired.

Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:14.0) Gecko/20100101 Firefox/14.0.1
Comment 3 Paul Rouget [:paul] 2012-07-27 09:11:53 PDT
Created attachment 646601 [details]
test case: worker
Comment 4 Paul Rouget [:paul] 2012-07-27 09:12:37 PDT
Created attachment 646603 [details]
test case (use this)
Comment 5 Paul Rouget [:paul] 2012-07-27 09:13:47 PDT
Created attachment 646604 [details]
test case (use this)
Comment 6 Marcin Kulik 2012-07-28 04:33:05 PDT
I've prepared another test html+js to demonstrate this bug: https://gist.github.com/3192915

You can observe that in FF v12-14 setInterval() works fine (proving that worker hasn't died and is still running) but setTimeout() stops triggering after a few iterations.
Comment 7 Kyle Huey [:khuey] (Exited; not receiving bugmail, email if necessary) 2012-08-07 17:39:27 PDT
We got this in a debugger and figured it out.
Comment 8 Kyle Huey [:khuey] (Exited; not receiving bugmail, email if necessary) 2012-08-08 10:48:11 PDT
Created attachment 650204 [details] [diff] [review]
Patch
Comment 9 Kyle Huey [:khuey] (Exited; not receiving bugmail, email if necessary) 2012-08-10 09:17:25 PDT
https://hg.mozilla.org/integration/mozilla-inbound/rev/7266ce1abf6b
Comment 10 Ryan VanderMeulen [:RyanVM] 2012-08-11 19:56:17 PDT
https://hg.mozilla.org/mozilla-central/rev/7266ce1abf6b

Note You need to log in before you can comment on or make changes to this bug.