Last Comment Bug 758042 - Worker messages received drifted from the order being sent
: Worker messages received drifted from the order being sent
Status: UNCONFIRMED
:
Product: Core
Classification: Components
Component: DOM: Workers (show other bugs)
: 12 Branch
: x86 Linux
: -- normal (vote)
: ---
Assigned To: Nobody; OK to take it and work on it
:
Mentors:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2012-05-23 15:36 PDT by Rex
Modified: 2012-06-25 12:14 PDT (History)
2 users (show)
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Attachments

Description Rex 2012-05-23 15:36:16 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

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() {
            if (area == null) {
                area = document.getElementById(areaId);
            }
            area.value = "";
        };
    }

    leftArea = new AreaController("leftText");

    lastTimestamp = "0";

    worker = new Worker("WebWorker.js");
    worker.onmessage = function(event) {
        var msg = event.data;

        var timestamp = msg.split(":")[1];
        if (lastTimestamp >= timestamp) {
            msg += " <<<";
        } else {
            lastTimestamp = timestamp;
        }

        leftArea.append(msg);
    }
</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
========================================
setInterval(function() {
    msg = "WebWorker:" + new Date().getTime();
    postMessage(msg);
}, 1111);



Actual results:

1, Within a couple of minutes of running MainUI.html, 
2, Firefox pops up a warning dialog (see below), 
3, and a message arrives in wrong order of being sent (see "<<<" marked line below).

========================================
Warning: Unresponsive script

A script on this page may be busy, or it may have stopped responding. You can stop the script now, or you can continue to see if the script will complete.

Script: file:///<...>/MainUI.html:28


========================================
WebWorker:1337810763261
WebWorker:1337810764372
WebWorker:1337810766594
WebWorker:1337810767705
WebWorker:1337810768816
WebWorker:1337810769926
WebWorker:1337810771038
WebWorker:1337810772150
WebWorker:1337810773260
WebWorker:1337810774371
WebWorker:1337810775482
WebWorker:1337810765483 <<<
WebWorker:1337810776593
WebWorker:1337810777704



Expected results:

The marked message should be 9 lines above its current position as its time stamp suggests.
Comment 1 Kyle Huey [:khuey] (khuey@mozilla.com) 2012-06-04 14:44:43 PDT
I think this is just the interaction with the slow script dialog.  The message being run when the slow script dialog fires will be delayed until the dialog is closed.
Comment 2 Rex 2012-06-05 12:39:53 PDT
Hi Kyle, I still think this is a wrong behavior and I stated my reasoning below. Hope to see your input soon.

I am not sure if the semantics of "messages should be received on the other side in the order of being sent by postMessage()" is defined in the web worker's spec. I'd guess that most of programmers will expect that in normal situations. When it comes to the slowness I'd expect some adjustments like:

1) If a message is slow, all messages after it should wait.

2) If a message is slow and a slow script dialog is being displayed, all messages after it should still wait until either of followings:

2.1) User clicked on Stop script: the message should be discarded, rest of messages continue as usual. This may break the program but user is aware of it.

2.2) User clicked on Continue: then all messages continue to wait until the the message finally arrives or case 2.1 happens on another dialog (I am assuming a slow dialog will display again repeatedly at a certain interval).
Comment 3 Rex 2012-06-25 12:14:52 PDT
Verified that it is still happening in version 13.0.1. However it is less frequent than in version 12. I had to wait for a couple of minutes to see it happen.

Version info: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:13.0) Gecko/20100101 Firefox/13.0.1

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