Closed Bug 2005953 Opened 1 month ago Closed 19 days ago

Prevent automatic suspension of event page when downloads.download() is awaiting user input via file chooser

Categories

(WebExtensions :: General, defect, P3)

defect

Tracking

(firefox149 fixed)

RESOLVED FIXED
149 Branch
Tracking Status
firefox149 --- fixed

People

(Reporter: robwu, Assigned: robwu)

References

(Blocks 2 open bugs)

Details

(Whiteboard: [addons-jira])

Attachments

(1 file)

See bug 2005952 for the motivation.

A work-around to limit the impact of bug 2005952 is to postpone event page termination while the downloads.download() call is blocked on user input (file saver dialog). I created a patch and it seems to work.

Depends on: 2005963
Severity: -- → S3
Status: NEW → ASSIGNED
Priority: -- → P3
Whiteboard: [addons-jira]
Pushed by rob@robwu.nl: https://github.com/mozilla-firefox/firefox/commit/169276ef54e1 https://hg.mozilla.org/integration/autoland/rev/d5c4850ed1c2 Keep event page alive when downloads.download() triggers file picker r=toolkit-telemetry-reviewers,janerik,rpl
Pushed by sstanca@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/6a7ee7ff1147 https://hg.mozilla.org/integration/autoland/rev/edf57ff63ea9 Revert "Bug 2005953 - Keep event page alive when downloads.download() triggers file picker r=toolkit-telemetry-reviewers,janerik,rpl" for causing xpcshell assertion failures.

Reverted this because it was causing xpcshell assertion failures.

Flags: needinfo?(rob)

The test did indeed fail on Windows, but not for the reason highlighted in comment 4. That assertion error is from a different test and tracked in bug 1993378.

The relevant failure log in the context of this bug is as follows. The logs show that the test is stuck waiting for the file to finish writing the content, waiting at https://hg-edge.mozilla.org/integration/autoland/rev/d5c4850ed1c2#l3.119 . This could be general slowness on the Windows test machine, or be a quirk from the way that downloads are processed on Windows. By default, waitForCondition waits for 5 seconds, which ought to be enough...

[task 2026-01-13T22:17:36.934+00:00] 22:17:36 INFO - "Calling downloads.download with URL blob:moz-extension://78efe15a-8bd0-4834-ab8e-9a57039f7b1b/7516fb1c-4aef-439e-bb8e-562576b6590c"
[task 2026-01-13T22:17:36.936+00:00] 22:17:36 INFO - "Waiting for file picker to have been shown."
[task 2026-01-13T22:17:36.936+00:00] 22:17:36 INFO - TEST-PASS | xpcshell-remote.toml:toolkit/components/extensions/test/xpcshell/test_ext_downloads_blob_url.js | test_download_blob_with_slow_file_picker - [test_download_blob_with_slow_file_picker : 69] File picker should show once - 1 == 1
[task 2026-01-13T22:17:36.936+00:00] 22:17:36 INFO - "Delaying file picker completion past background idle timeout"
[task 2026-01-13T22:17:37.046+00:00] 22:17:37 INFO - "Returning from file picker after background idle timeout passed"

[task 2026-01-13T22:17:37.047+00:00] 22:17:37 INFO - TEST-PASS | xpcshell-remote.toml:toolkit/components/extensions/test/xpcshell/test_ext_downloads_blob_url.js | test_download_blob_with_slow_file_picker - [test_download_blob_with_slow_file_picker : 106] File picker was shown once - 1 == 1
[task 2026-01-13T22:17:37.051+00:00] 22:17:37 INFO - "Waiting until blob was saved to chosen file at C:\Users\task_176834088148911\AppData\Local\Temp\xpc-profile-ejlz0fa2\dldir\result.txt"
[task 2026-01-13T22:17:37.052+00:00] 22:17:37 INFO - "Waiting until file was fully written"
[task 2026-01-13T22:17:37.052+00:00] 22:17:37 INFO - "Clearing pref "extensions.background.idle.timeout""
[task 2026-01-13T22:17:37.052+00:00] 22:17:37 INFO - TEST-ERROR | xpcshell-remote.toml:toolkit/components/extensions/test/xpcshell/test_ext_downloads_blob_url.js | Unexpected exception undefined - timed out after 50 tries.

After inspecting relevant I/O code, I think that I figured out the issue.

On Windows, nsIFile.size (impl)'s return value is constant after the first access because the stat result is cached. A potential work-around could be to call file.exists(), because that marks the file instance as dirty to force a new stat.

On macOS (where I tested the patch), nsIFile.size returns the latest state of the file. It used to also have a stat cache, but that was removed 17 years ago in bug 456435.

Pushed by rob@robwu.nl: https://github.com/mozilla-firefox/firefox/commit/b55685714ee9 https://hg.mozilla.org/integration/autoland/rev/2c19ff287855 Keep event page alive when downloads.download() triggers file picker r=toolkit-telemetry-reviewers,janerik,rpl
Pushed by amarc@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/357c961a15d3 https://hg.mozilla.org/integration/autoland/rev/847ecdc71455 Revert "Bug 2005953 - Keep event page alive when downloads.download() triggers file picker r=toolkit-telemetry-reviewers,janerik,rpl" for causing xpcshell failures @ test_ext_downloads_blob_url

Backed out for causing xpcshell failures

Ah... I see what is going on.

Despite automation closing bug 2005963, the patch to that bug has not actually landed, because it was backed out in comment 4 here. So, what I will be doing is to re-open bug 2005963, re-parent the patch to the patch from that other bug, and reland the whole stack.

I drew that conclusion, because obviously the revert from comment 4 includes the other bug, while the log of the failing land attempt contains this error:

JavaScript Error: "can't access property "window", global.windowTracker.getTopWindow() is null" {file: "chrome://extensions/content/parent/ext-downloads.js" line: 931}]

That line points to the current in-tree code at https://searchfox.org/firefox-main/rev/5917a9f2af3294b27a325371c5c499e7dd9554fd/toolkit/components/extensions/parent/ext-downloads.js#931
... which is something that the patch at bug 2005963 was meant to fix.

Flags: needinfo?(rob)
Pushed by rob@robwu.nl: https://github.com/mozilla-firefox/firefox/commit/451bc7ed4ac8 https://hg.mozilla.org/integration/autoland/rev/1c660c3ed8b3 Keep event page alive when downloads.download() triggers file picker r=toolkit-telemetry-reviewers,janerik,rpl
Status: ASSIGNED → RESOLVED
Closed: 19 days ago
Resolution: --- → FIXED
Target Milestone: --- → 149 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: