Closed Bug 2081772 Opened 1 month ago Closed 12 days ago

toolkit/components/extensions/test/xpcshell/test_ext_experiments.js fails with Android isolated process

Categories

(GeckoView :: General, defect)

All
Android
defect

Tracking

(Not tracked)

RESOLVED DUPLICATE of bug 1976115

People

(Reporter: jnicol, Unassigned, NeedInfo)

References

(Blocks 1 open bug)

Details

Rob's analysis from bug 1709961:

TEST-UNEXPECTED-TIMEOUT | xpcshell-remote.toml:toolkit/components/extensions/test/xpcshell/test_ext_experiments.js | Test timed out

The log viewer doesn't show any useful information, but I downloaded the logcat file and filtered it to exclude logspam from bug 1844829 (2M lines out of 2.4M are logspam, 481 MB -> 97 MB):

07-01 20:11:29.056 17741 17762 I Gecko   : {"action":"test_status","time":1751400689056,"thread":null,"pid":null,"source":"xpcshell/head.js","test":"xpcshell-remote.toml:toolkit/components/extensions/test/xpcshell/test_ext_experiments.js","subtest":"test_unbundled_experiments","status":"PASS","message":"[test_unbundled_experiments : 144] typeof browser.experiments - Expected: object, Actual: object - true == true"}
07-01 20:11:29.061 17741 17762 I Gecko   : {"action":"test_status","time":1751400689061,"thread":null,"pid":null,"source":"xpcshell/head.js","test":"xpcshell-remote.toml:toolkit/components/extensions/test/xpcshell/test_ext_experiments.js","subtest":"test_unbundled_experiments","status":"PASS","message":"[test_unbundled_experiments : 144] typeof browser.experiments.foo - Expected: object, Actual: object - true == true"}
07-01 20:11:29.065 17741 17762 I Gecko   : {"action":"test_status","time":1751400689065,"thread":null,"pid":null,"source":"xpcshell/head.js","test":"xpcshell-remote.toml:toolkit/components/extensions/test/xpcshell/test_ext_experiments.js","subtest":"test_unbundled_experiments","status":"PASS","message":"[test_unbundled_experiments : 144] typeof browser.experiments.foo.child - Expected: function, Actual: function - true == true"}
07-01 20:11:29.067 17741 17762 I Gecko   : {"action":"test_status","time":1751400689067,"thread":null,"pid":null,"source":"xpcshell/head.js","test":"xpcshell-remote.toml:toolkit/components/extensions/test/xpcshell/test_ext_experiments.js","subtest":"test_unbundled_experiments","status":"PASS","message":"[test_unbundled_experiments : 144] typeof browser.experiments.foo.parent - Expected: function, Actual: function - true == true"}
07-01 20:11:29.070 17741 17762 I Gecko   : {"action":"test_status","time":1751400689070,"thread":null,"pid":null,"source":"xpcshell/head.js","test":"xpcshell-remote.toml:toolkit/components/extensions/test/xpcshell/test_ext_experiments.js","subtest":"test_unbundled_experiments","status":"PASS","message":"[test_unbundled_experiments : 144] foo.child() - Expected: child, Actual: child - true == true"}
07-01 20:11:29.086 17797 17814 E WebExtensions: [JavaScript Error: "uncaught exception: Error opening input stream (invalid filename?): jar:file:///data/local/tmp/test_root/xpc/p/075eef98-6c61-489e-a5e9-5f404dba5f20/temp/generated-extension-1.xpi!/child.js" {file: "moz-extension://05cd66f0-93eb-4960-a143-adcef1347a6e/%7Bc879248e-c25b-446c-a4ba-22e659864a1b%7D.js" line: 73}]
07-01 20:11:29.086 17797 17814 E WebExtensions: background@moz-extension://05cd66f0-93eb-4960-a143-adcef1347a6e/%7Bc879248e-c25b-446c-a4ba-22e659864a1b%7D.js:73:3
07-01 20:11:29.086 17797 17814 E WebExtensions: async*@moz-extension://05cd66f0-93eb-4960-a143-adcef1347a6e/%7Bc879248e-c25b-446c-a4ba-22e659864a1b%7D.js:73:5
07-01 20:11:29.097 17741 17762 D GeckoViewConsole: onExtensionReady {ed34fa23-c3fc-44ee-a512-3a6349ac99cf}
07-01 20:11:29.106 17741 17762 I Gecko   : {"action":"test_status","time":1751400689106,"thread":null,"pid":null,"source":"xpcshell/head.js","test":"xpcshell-remote.toml:toolkit/components/extensions/test/xpcshell/test_ext_experiments.js","subtest":"test_unbundled_experiments","status":"PASS","message":"[test_unbundled_experiments : 144] await foo.parent() - Expected: parent, Actual: parent - true == true"}
07-01 20:11:29.107 17741 17762 I Gecko   : {"action":"test_status","time":1751400689107,"thread":null,"pid":null,"source":"xpcshell/head.js","test":"xpcshell-remote.toml:toolkit/components/extensions/test/xpcshell/test_ext_experiments.js","subtest":"test_unbundled_experiments","status":"PASS","message":"[test_unbundled_experiments : 144] typeof browser.experiments.crunk - Expected: object, Actual: object - true == true"}
07-01 20:11:29.109 17741 17762 I Gecko   : {"action":"log","time":1751400689108,"thread":null,"pid":null,"source":"xpcshell/head.js","level":"INFO","message":"\"CONSOLE_MESSAGE: (error) [JavaScript Error: \"uncaught exception: Error opening input stream (invalid filename?): jar:file:///data/local/tmp/test_root/xpc/p/075eef98-6c61-489e-a5e9-5f404dba5f20/temp/generated-extension-1.xpi!/child.js\" {file: \"moz-extension://05cd66f0-93eb-4960-a143-adcef1347a6e/%7Bc879248e-c25b-446c-a4ba-22e659864a1b%7D.js\" line: 73}]\nbackground@moz-extension://05cd66f0-93eb-4960-a143-adcef1347a6e/%7Bc879248e-c25b-446c-a4ba-22e659864a1b%7D.js:73:3\nasync*@moz-extension://05cd66f0-93eb-4960-a143-adcef1347a6e/%7Bc879248e-c25b-446c-a4ba-22e659864a1b%7D.js:73:5\n\""}

The log show that an error is thrown while executing typeof browser.experiments.crunk.child because the child.js file declared in apiExtension cannot be loaded: uncaught exception: Error opening input stream (invalid filename?): jar:file:///data/local/tmp/test_root/xpc/p/075eef98-6c61-489e-a5e9-5f404dba5f20/temp/generated-extension-1.xpi!/child.js.

Oddly enough, other tests in the file also load (a different) child.js in the extension process, which works just fine.

Oddly enough, other tests in the file also load (a different) child.js in the extension process, which works just fine.

Claude has this explanation:

What gets loaded, and when

A privileged extension can declare experiment_apis. Each API has a parent script and a child script inside the extension's xpi. In test_unbundled_experiments, crunk@experiments.addons.mozilla.org provides experiments.crunk, and a second extension uses it.

ExtensionData.parseManifest turns each child script into module data, which is sent to the extension process. In the extension process, browser.experiments.crunk is a lazy getter. The first time the background script touches it (here typeof browser.experiments.crunk), the getter runs synchronously:

getAPI → SchemaAPIManager.loadModule(name) → Services.scriptloader.loadSubScriptWithOptions(module.url, …) in ExtensionCommon.sys.mjs

That load is what failed.

The old path: jar:file: opened directly by the child

  1. moduleData set url: this.rootURI.resolve(data.script). For a packed extension, rootURI is the xpi itself, so the URL was:
    jar:file:///data/local/tmp/.../temp/generated-extension-1.xpi!/child.js
  2. loadSubScript opens a channel to that URL and reads it synchronously. The error in logcat, "Error opening input stream (invalid filename?)", is what it reports when that open fails.
  3. A jar: URL gives an nsJARChannel. nsJARChannel::Open (modules/libjar/nsJARChannel.cpp):
    • LookupFile() takes the inner file: URL and makes an nsIFile for the xpi's path.
    • CreateJarInput(jarCache, …) asks the process-wide zip cache for a reader: nsZipReaderCache::GetZip(file) in nsJAR.cpp.
  4. GetZip looks the archive up by "file:" + file->GetPersistentDescriptor(), i.e. its path.
    • Cache hit: it reuses the already-open nsJAR, and nothing touches the filesystem.
    • Cache miss: it does new nsJAR() and zip->Open(zipFile). That opens the file by path, in this process.
  5. On a miss in an isolated process, that open fails. An isolated process runs as its own sandboxed user with no access to the app's files or /data/local/tmp. A regular Android content process runs as the app's user, so it can open the file. On desktop, the sandbox file broker allows reads under <profile>/extensions (SandboxBrokerPolicyFactory.cpp).

So the child script itself was fine. What failed was the child process opening the xpi by path.

Why the bundled foo experiment worked anyway

Its URL was also a raw jar:file: URL, into generated-extension.xpi. But that extension's background page had already been loaded through moz-extension: URLs (path below). Those loads open the xpi from a file descriptor the parent sends, and put the open archive in the same zip cache. That cache is keyed by the xpi's real path; I infer that FileDescriptorFile reports the original file's path, but couldn't find its source to confirm it. So when foo's jar:file: child script was loaded later, step 4 was a cache hit and the file was never opened.

crunk's xpi is never loaded through moz-extension: in the extension process, so its lookup is a cache miss. The cache also drops entries: nsZipReaderCache evicts the oldest released archive once it's over its size limit, and it registers for memory-pressure and flush-cache-entry. So even the bundled case only worked by luck.

Rob, do you have any suggestions for how this could be fixed?

Flags: needinfo?(rob)

This sounds like the same issue as bug 1976115. I mentioned the same symptom before at https://bugzilla.mozilla.org/show_bug.cgi?id=1976115#c2

Flags: needinfo?(rob)
See Also: → 1976115

The severity field is not set for this bug.
:owlish, could you have a look please?

For more information, please visit BugBot documentation.

Flags: needinfo?(bugzeeeeee)

We can close this as a dup of bug 1976115. The test is now passing

Status: NEW → RESOLVED
Closed: 12 days ago
Duplicate of bug: 1976115
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.