New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 835968 link

Starred by 3 users

Issue metadata

Status: Assigned
Owner:
Cc:
Components:
EstimatedDays: ----
NextAction: 2018-07-14
OS: Linux , Windows , Chrome , Mac
Pri: 2
Type: Bug



Sign in to add a comment

extension that specifies a devtools page in manifest breaks messaging garbage collection

Reported by drol...@yahoo.com, Apr 23 2018

Issue description

UserAgent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.117 Safari/537.36

Steps to reproduce the problem:
1. Create an extension with manifest that includes a background page and content script.
2. In background context, call chrome.runtime.onMessage.addListener(()=>null);
3. In content script context, call chrome.runtime.sendMessage(null,"",null,() => console.log(chrome.runtime.lastError.message));
4. The devtools console will now display the lastError text of "The message port closed before a response was received." This is correct because the message sender included the callback argument in sendMessage and it was never called by an onMessage listener in the background.
5. Now, in the manifest, set the previously unset property of "devtools_page" to a simple html page (content not necessary in the page) and reload extension.
6. Now make the calls in points 3 and 4. Nothing is displayed in the console. The message senders callback is never triggered. 

What is the expected behavior?
The message senders callback function should be called regardless of whether the extension includes a devtools page. In the callback, the property chrome.runtime.lastError should be set to "The message port closed before a response was received."

What went wrong?
In the version of these extension with a devtools page, the callback is never triggered and the sender is left waiting for notification. This is a big problem for the extension developer and may stop garbage collection of objects associated with the sender's callback.

Did this work before? N/A 

Does this work in other browsers? N/A

Chrome version: 66.0.3359.117  Channel: stable
OS Version: ubuntu 16.04
Flash Version: 

This behavior is odd because devtools scripts cannot use the chrome.runtime.onMessage event to listen for messages (devtools scripts can only send messages). So I'm not sure why the simple existence of a devtools page breaks the messaging system. You can test this situation with the attached zip by just removing/adding the manifest property "devtools_page" and reloading.
 
test_messaging.zip
1.3 KB Download

Comment 1 by drol...@yahoo.com, Apr 23 2018

Correction - in point 6 above, I meant "in points 2 and 3", not "3 and 4".
Labels: Needs-Triage-M66
Components: Platform>DevTools
Labels: Needs-Feedback Triaged-ET
Tested the issue on chrome reported version 66.0.3359.117 using Ubuntu 14.04 with steps mentioned below:
1) Launched chrome reported version and installed the extension provided in comment# 0
2) In chrome://extensions, for the extension installed, clicked on "background page", developer tools opened
3) In console entered call chrome.runtime.onMessage.addListener(()=>null); and chrome.runtime.sendMessage(null,"",null,() => console.log(chrome.runtime.lastError.message)); got the output as "Could not establish connection. Receiving end does not exist".

@Reporter: Please find the attached screencast for your reference and provide your feedback on it which help in further triaging it, could you please let us know if this issue is specific to Ubuntu 16.04, if possible please provide the screencast of the issue which help us in better understanding it.

Thanks!
835968.ogv
6.7 MB View Download

Comment 4 by drol...@yahoo.com, Apr 26 2018

Thanks for the response. 

You can't call sendMessage from the background when the listener is also in the background (the background doesn't receive messages sent from background, that's why you get the "can't connect message"). You should call sendMessage from a content script context (as described in point 3) if you want to do this on your own. Then continue with steps 4 to 6.

The sample extension that I provided already handles these steps. You just need to review the content devtools console after installation and loading "www.example.com" into a tab to see the message. Then edit the manifest as described in point 5 (you can use the index.html in my sample zip as devtools page) and reload extension and example.com. You should see the results as intended (no message now). Let me know if I'm not explaining clearly.
Project Member

Comment 5 by sheriffbot@chromium.org, Apr 26 2018

Cc: viswa.karala@chromium.org
Labels: -Needs-Feedback
Thank you for providing more feedback. Adding the requester to the cc list.

For more details visit https://www.chromium.org/issue-tracking/autotriage - Your friendly Sheriffbot
Cc: krajshree@chromium.org
Labels: Needs-Feedback
Tested the issue on ubuntu 17.10 using chrome latest stable #67.0.3396.62.

Attached a screen cast for reference.

Following are the steps followed to reproduce the issue.
------------
1. Reviewed the content devtools console after installation of "test_messaging" extension and loading "www.example.com" into a tab.
2. Observed a message in dev tools console as "The message port closed before a response was received."
3. Edited the manifest.json file by removing the line "devtools_page": "index.html",
4. Reloaded extension and example.com and observed that the extension got disabled and did not find any message in the console.

droland@ - Could you please check the attached screen cast and please let us know if anything missed from our end.

Thanks...!!
835968.webm
5.8 MB View Download

Comment 7 by drol...@yahoo.com, Jun 1 2018

Yes, your last screen cast demonstrates the problem. From my prior experiences on this bug system, I think rob@robwu.nl might be a good person to consider this issue. He seems to know the extension messaging system well.
Project Member

Comment 8 by sheriffbot@chromium.org, Jun 1 2018

Labels: -Needs-Feedback
Thank you for providing more feedback. Adding the requester to the cc list.

For more details visit https://www.chromium.org/issue-tracking/autotriage - Your friendly Sheriffbot
Labels: M-69 Target-69 FoundIn-69 OS-Mac OS-Windows
Status: Untriaged (was: Unconfirmed)
Able to reproduce the issue on Mac 10.13.3, Win-10 and Ubuntu 17.10 using chrome latest stable #67.0.3396.62 and latest canary #69.0.3449.2.
This is a non-regression issue as it is observed from M60 old builds. 

Hence, marking it as untriaged to get more inputs from dev team.

Thanks...!!

Comment 10 by kozy@chromium.org, Jun 11 2018

Owner: rob@robwu.nl
Status: Assigned (was: Untriaged)
based on #7 comment.

Comment 11 by rob@robwu.nl, Jun 20 2018

Components: -Platform>DevTools Platform>Extensions
Labels: OS-Chrome
NextAction: 2018-07-14
TL;DR this is not specific to devtools_page. Any extension page (including iframes) without an onMessage listener will cause this issue.

Comment 6's reproduction is flawed. At the second reproduction step, manifest.json becomes an invalid JSON file (because the "devtools_page" value is removed without removing the key). Therefore any conclusions that rely on the video are invalid.

I verified that the bug exists, as follows:
1. Load extension.
2. Open example.com
3. Open DevTools console
   GOOD: Confirm that "The message port closed before a response was received." is shown.
4. Reload the page while the DevTools is still open (so the devtools_page is still open).
   BAD: The message from step 3 is not shown again.

Sanity check, to verify that the issue is caused by the mere existence of a devtools_page:
5. Open example.com in a new tab (without closing the tabs from the previous steps).
6. Open DevTools console.
7. BAD: The message from step 3 is not shown again.


When devtools_page was introduced, the devtools page ran in the process of the DevTools.
With out-of-process iframes (OOPIF) for extensions, it runs in the extension process instead.

And indeed, the same issue can be reproduced if you open a regular extension page in a new tab (e.g. chrome-extension://EXTENSIONID/manifest.json), or even a new frame in the background page.

This bug is caused by the optimization at:
https://chromium.googlesource.com/chromium/src/+/267468938e712a25010fb84ee32522a371fbbf23/extensions/browser/api/messaging/extension_message_port.cc#294

The listener in the background page ensures that port_created is true at
https://chromium.googlesource.com/chromium/src/+/90a2d3e77ac698d2b419144a8d87ed9306c1b1ac/extensions/renderer/renderer_messaging_service.cc#80

The early returns in RendererMessagingService::DispatchOnConnectToScriptContext prevent the close messages from being sent:
https://chromium.googlesource.com/chromium/src/+/90a2d3e77ac698d2b419144a8d87ed9306c1b1ac/extensions/renderer/renderer_messaging_service.cc#158

Consequently the ExtensionMessagePort does not know that all recipients have rejected the port, and the port is kept open until the page is unloaded.

I don't have time in the coming weeks to work on this, but patches are welcome.

Sign in to add a comment