Closed Bug 1622124 Opened 9 months ago Closed 8 months ago

BroadcastChannel receives messages in onmessage after channel has been closed

Categories

(Core :: DOM: postMessage, defect)

72 Branch
defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla76
Tracking Status
firefox76 --- fixed

People

(Reporter: dahaden, Assigned: baku)

References

()

Details

Attachments

(1 file, 1 obsolete file)

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:72.0) Gecko/20100101 Firefox/72.0

Steps to reproduce:

Open two tabs on the same domain (https://developer.mozilla.org/en-US/docs/Web/API/BroadcastChannel will do).

Run the following code in console on Tab 1.

const channel = new BroadcastChannel("my key");

let setClosed = false;
channel.onmessage = (num) => {
  console.log("Received:", num.data);
  if (!setClosed) {
      console.log("closing");
      channel.close();
      console.log("closed");
  }
  setClosed = true;
};

This will create a new broadcast channel, and listen to messages. On the first message, we will close the channel.

In Tab 2, open console and run the following code.

const channel = new BroadcastChannel("my key");
for(var i = 0; i < 100; i++) {
  channel.postMessage(i);
}

This will send 100 messages to Tab 1.

Go back to Tab 1 to view the results.

Actual results:

In Tab 1, you should see the first message close the channel, followed by (in my testing) ~30-40 more events received after the channel has been closed.

Expected results:

Only the first message received and no more.

I had also seen https://bugzilla.mozilla.org/show_bug.cgi?id=1405911 which sounds like the same bug, but had been marked as "Status:
RESOLVED INCOMPLETE"

And looking at the BroadcastChannel spec, it states:

For each BroadcastChannel object destination in destinations, queue a task on the DOM manipulation task source of destination's relevant agent's event loop that runs the following steps.

The first step here being "If destination's closed flag is true, then return." which is what I believe may not be happening.

Component: Untriaged → DOM: Core & HTML
Product: Firefox → Core
Component: DOM: Core & HTML → DOM: postMessage

baku, you were fixing some of the BC closing issues relatively recently, but perhaps those were about workers only?

Flags: needinfo?(amarchesini)
Assignee: nobody → amarchesini
Flags: needinfo?(amarchesini)
Pushed by amarchesini@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/43843f5a7d32
BroadcastChannel receives messages in onmessage after channel has been closed, r=smaug
Backout by btara@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/4fcb55fd1786
Backed out changeset 43843f5a7d32 for permafails on webmessaging/broadcastchannel/basics.html CLOSED TREE

Backed out changeset 43843f5a7d32 (Bug 1622124) for permafails on webmessaging/broadcastchannel/basics.html CLOSED TREE

Push with failures: https://treeherder.mozilla.org/#/jobs?repo=autoland&searchStr=android%2C7.0%2Cx86-64%2Copt%2Cweb%2Cplatform%2Ctests%2Ctest-android-em-7.0-x86_64%2Fopt-geckoview-web-platform-tests-e10s&fromchange=e144f3d78dfaeaf1b26a4997051935b60902b4a0&tochange=4fcb55fd17861ea5d642f7e5a08e5f3901736919&selectedJob=293334021

Backout link: https://hg.mozilla.org/integration/autoland/rev/4fcb55fd17861ea5d642f7e5a08e5f3901736919

Failure log: https://treeherder.mozilla.org/logviewer.html#/jobs?job_id=293334021&repo=autoland&lineNumber=9063

[task 2020-03-16T14:50:24.879Z] 14:50:24     INFO - TEST-START | /webmessaging/broadcastchannel/basics.html
[task 2020-03-16T14:50:25.153Z] 14:50:25     INFO - 
[task 2020-03-16T14:50:25.153Z] 14:50:25     INFO - TEST-PASS | /webmessaging/broadcastchannel/basics.html | postMessage results in correct event 
[task 2020-03-16T14:50:25.153Z] 14:50:25     INFO - TEST-PASS | /webmessaging/broadcastchannel/basics.html | messages are delivered in port creation order 
[task 2020-03-16T14:50:25.153Z] 14:50:25     INFO - TEST-PASS | /webmessaging/broadcastchannel/basics.html | messages aren't delivered to a closed port 
[task 2020-03-16T14:50:25.153Z] 14:50:25     INFO - TEST-PASS | /webmessaging/broadcastchannel/basics.html | messages aren't delivered to a port closed after calling postMessage. 
[task 2020-03-16T14:50:25.153Z] 14:50:25     INFO - TEST-PASS | /webmessaging/broadcastchannel/basics.html | closing and creating channels during message delivery works correctly 
[task 2020-03-16T14:50:25.153Z] 14:50:25     INFO - TEST-UNEXPECTED-PASS | /webmessaging/broadcastchannel/basics.html | Closing a channel in onmessage prevents already queued tasks from firing onmessage events - expected FAIL
[task 2020-03-16T14:50:25.153Z] 14:50:25     INFO - TEST-INFO | expected FAIL
[task 2020-03-16T14:50:25.475Z] 14:50:25     INFO - TEST-OK | /webmessaging/broadcastchannel/basics.html | took 595ms
Flags: needinfo?(amarchesini)
Flags: needinfo?(amarchesini)
Pushed by amarchesini@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/b92e26454745
BroadcastChannel receives messages in onmessage after channel has been closed, r=smaug
Backout by malexandru@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/7a683c47bf43
Backed out changeset b92e26454745 for causing failures in test_broadcastchannel_close2.html
Attachment #9133524 - Attachment is obsolete: true
Attachment #9133524 - Attachment is obsolete: false
Attachment #9133765 - Attachment is obsolete: true
Duplicate of this bug: 1447586
Pushed by amarchesini@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/b9badd1ee675
BroadcastChannel receives messages in onmessage after channel has been closed, r=smaug
Status: UNCONFIRMED → RESOLVED
Closed: 8 months ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla76
You need to log in before you can comment on or make changes to this bug.