Bug 1643214 Comment 0 Edit History

Note: The actual edited comment in the bug view page will always show the original commenter’s name and original timestamp.

I still couldn't find out the minimum condition to reproduce, but there is a reproducibility on a real addon, so I report this.

On some situations `runtime.onMessage` listener cannot return a response asynchronously via a Promise. When the problem happens the sender simply gets `undefined` response unexpectedly and immediately, even if the promise returned by a listener is not resolved yet.

# Steps to reproduce

I've tried these steps with the mozregression for mozilla-central builds between 2020-05-31 and 2020-06-01.

1. Start Nightly.
2. Install the addon: https://addons.mozilla.org/ja/firefox/addon/tree-style-tab/
3. A sidebar panel provided by the addon is loaded. Please do all following steps on the sidebar.
4. Open two more blank tabs and construct a tree of tabs by drag and drop. Assume that finally there are three tabs:
   * Tab A (initially opened tab)
   * Tab B (startup tab opened by the addon automatically)
   * Tab C (1st new blank tab)
      * Tab D (a child of C, 2nd new blank tab)
5. Collapse a tree by clicking the down chevron of the tab C.
6. Middle-click on the tab C (or click the "X" button of the tab C) to close the tree.
7. The addon shows a confirmation dialog to close multiple tabs. Chose the "Close tabs" button in the dialog.

# Expected result

* Tabs C and D are closed.

# Actual result

* Tabs C and D are still there.

# Background of the problem

What expectedly happens when you try to close tabs is:

1. The sidebar panel sends a message to the background page via `runtime.sendMessag()`. 
2. The listener in the background page receives the message and returns a Promise.
3. The background page shows a confirmation dialog.
4. After the dialog is closed, the Promise returned at the step 2 is resolved with the result.
5. The sidebar panel gets the resolved result, and sends another message to request close tabs to the background page based on the resolved result.

On the other hand, what actually happens is:

1. The sidebar panel sends a message to the background page via `runtime.sendMessag()`. 
2. The listener in the background page receives the message and returns a Promise.
3. The sidebar panel gets a value `undefined` as the resolved result, and gives up to confinue post processes.
4. The background page shows a confirmation dialog.
5. After the dialog is closed, the Promise returned at the step 2 is resolved with the result.

# Environment

Windows 10, the information shown in the mozregression for the first bad build:

```
app_name: firefox
build_date: 2020-06-01
build_file: C:\Users\***\.mozilla\mozregression\persist\2020-06-01--mozilla-central--firefox-79.0a1.en-US.win64.zip
build_type: nightly
build_url: https://archive.mozilla.org/pub/firefox/nightly/2020/06/2020-06-01-21-42-28-mozilla-central/firefox-79.0a1.en-US.win64.zip
changeset: bc973d369db58faf254ddcef201089dc28e6d3be
pushlog_url: https://hg.mozilla.org/mozilla-central/pushloghtml?fromchange=548ffce7ad571850fdcb024ae3459855230ebd35&tochange=bc973d369db58faf254ddcef201089dc28e6d3be
repo_name: mozilla-central
repo_url: https://hg.mozilla.org/mozilla-central
```
I still couldn't find out the minimum condition to reproduce, but there is a reproducibility on a real addon, so I report this.

On some situations `runtime.onMessage` listener cannot return a response asynchronously via a Promise. When the problem happens the sender simply gets `undefined` response unexpectedly and immediately, even if the promise returned by a listener is not resolved yet.

# Steps to reproduce

I've tried these steps with the mozregression for mozilla-central builds between 2020-05-31 and 2020-06-01.

1. Start Nightly.
2. Install the addon: https://addons.mozilla.org/ja/firefox/addon/tree-style-tab/
3. A sidebar panel provided by the addon is loaded. Please do all following steps on the sidebar.
4. Open two more blank tabs and construct a tree of tabs by drag and drop. Assume that finally there are three tabs:
   * Tab A (initially opened tab)
   * Tab B (startup tab opened by the addon automatically)
   * Tab C (1st new blank tab)
      * Tab D (a child of C, 2nd new blank tab)
5. Collapse a tree by clicking the down chevron of the tab C.
6. Middle-click on the tab C (or click the "X" button of the tab C) to close the tree.
7. The addon shows a confirmation dialog to close multiple tabs. Chose the "Close tabs" button in the dialog.

# Expected result

* Tabs C and D are closed.

# Actual result

* Tabs C and D are still there.

# Background of the problem

What expectedly happens when you try to close tabs is:

1. The sidebar panel sends a message to the background page via `runtime.sendMessag()`. 
   * https://github.com/piroor/treestyletab/blob/24caa7a3ebbe32475d0342e18c4cedb928df2ecd/webextensions/sidebar/mouse-event-listener.js#L577
   * https://github.com/piroor/treestyletab/blob/24caa7a3ebbe32475d0342e18c4cedb928df2ecd/webextensions/sidebar/sidebar.js#L562
2. The listener in the background page receives the message and returns a Promise.
   * https://github.com/piroor/treestyletab/blob/24caa7a3ebbe32475d0342e18c4cedb928df2ecd/webextensions/background/handle-misc.js#L375
3. The background page shows a confirmation dialog.
   * https://github.com/piroor/treestyletab/blob/24caa7a3ebbe32475d0342e18c4cedb928df2ecd/webextensions/background/background.js#L452
4. After the dialog is closed, the Promise returned at the step 2 is resolved with the result.
   * https://github.com/piroor/treestyletab/blob/24caa7a3ebbe32475d0342e18c4cedb928df2ecd/webextensions/background/background.js#L529
5. The sidebar panel gets the resolved result, and sends another message to request close tabs to the background page based on the resolved result.
   * https://github.com/piroor/treestyletab/blob/24caa7a3ebbe32475d0342e18c4cedb928df2ecd/webextensions/sidebar/mouse-event-listener.js#L578

On the other hand, what actually happens is:

1. The sidebar panel sends a message to the background page via runtime.sendMessag().
2. The listener in the background page receives the message and returns a Promise.
3. The sidebar panel gets a value undefined as the resolved result, and gives up to continue post processes.
4. The background page shows a confirmation dialog.
5. After the dialog is closed, the Promise returned at the step 2 is resolved with the result.

# Environment

Windows 10, the information shown in the mozregression for the first bad build:

```
app_name: firefox
build_date: 2020-06-01
build_file: C:\Users\***\.mozilla\mozregression\persist\2020-06-01--mozilla-central--firefox-79.0a1.en-US.win64.zip
build_type: nightly
build_url: https://archive.mozilla.org/pub/firefox/nightly/2020/06/2020-06-01-21-42-28-mozilla-central/firefox-79.0a1.en-US.win64.zip
changeset: bc973d369db58faf254ddcef201089dc28e6d3be
pushlog_url: https://hg.mozilla.org/mozilla-central/pushloghtml?fromchange=548ffce7ad571850fdcb024ae3459855230ebd35&tochange=bc973d369db58faf254ddcef201089dc28e6d3be
repo_name: mozilla-central
repo_url: https://hg.mozilla.org/mozilla-central
```

Back to Bug 1643214 Comment 0