Closed Bug 2021136 Opened 6 months ago Closed 3 months ago

toResizableBuffer is not working with WasmWorkers in Firefox 148.0 (64-bit)

Categories

(Core :: JavaScript: WebAssembly, defect, P2)

Firefox 148
defect

Tracking

()

RESOLVED FIXED
154 Branch
Tracking Status
firefox153 --- fixed
firefox154 --- fixed

People

(Reporter: arepko, Assigned: jpages)

Details

Attachments

(3 files, 2 obsolete files)

Steps to reproduce:

  1. new WebAssembly.Memory({ initial: 1, maximum: 10, shared: true })
  2. Call .toResizableBuffer() — succeeds, returns buffer with resizable = undefined
  3. postMessage({ memory }) to a Worker — succeeds on the sender side
  4. Worker never receives the message — no error, no message error, complete silence
    Without step 2, everything works perfectly

Logs for example:
[10:17:33 PM] \n=== Test: WITHOUT toResizableBuffer ===
[10:17:33 PM] Created WebAssembly.Memory (shared): buffer.byteLength = 65536
[10:17:33 PM] typeof memory.toResizableBuffer = function
[10:17:33 PM] Posting memory to worker...
[10:17:33 PM] postMessage succeeded (main thread side)
[10:17:33 PM] Worker result (WITHOUT toResizableBuffer):
[10:17:33 PM] received keys = memory, label
[10:17:33 PM] typeof memory = object
[10:17:33 PM] isUndefined = false
[10:17:33 PM] isNull = false
[10:17:33 PM] constructor = Memory
[10:17:33 PM] buffer.byteLength = 65536
[10:17:33 PM] buffer.constructor = SharedArrayBuffer
[10:17:33 PM] buffer.resizable = false
[10:17:33 PM] >>> PASS: memory is defined in worker <<<
[10:17:34 PM] \n=== Test: WITH toResizableBuffer ===
[10:17:34 PM] Created WebAssembly.Memory (shared): buffer.byteLength = 65536
[10:17:34 PM] typeof memory.toResizableBuffer = function
[10:17:34 PM] Called toResizableBuffer() — returned buffer byteLength = 65536, resizable = undefined, maxByteLength = 655360
[10:17:34 PM] memory.buffer after conversion: byteLength = 65536
[10:17:34 PM] Posting memory to worker...
[10:17:34 PM] postMessage succeeded (main thread side)
[10:17:37 PM] >>> TIMEOUT: Worker never responded after 3s (WITH toResizableBuffer) <<<

In a real project, the WASM is built with emscripten, and it crashes if a ResizableBuffer is present in the code/scope (not even called!), with the " wasmMemory is not defined error.

Actual results:

The worker never receives the message — no error, no message error, complete silence

Expected results:

Worker receives the message or toResizableBuffer is not available.

The Bugbug bot thinks this bug should belong to the 'Core::JavaScript: WebAssembly' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.

Component: Untriaged → JavaScript: WebAssembly
Product: Firefox → Core
Assignee: nobody → ydelendik
Severity: -- → S3
Priority: -- → P2

It is a StructureClone+shared resizable buffer defect. In this case it fails to de-serialize a growable memory. It is probably just a simple fix to remove the payload.toObject().as<SharedArrayBufferObject>().isGrowable() check at https://searchfox.org/firefox-main/source/js/src/vm/StructuredClone.cpp#3027

We just came across the exact same bug in emscripten: https://github.com/emscripten-core/emscripten/issues/27118

Would be great to get this fixed, although it sounds like we will likely need to have a userAgent probe in there for the foreseeable to avoid using this feature on certain shipping firefox versions?

Assignee: ydelendik → jpages
Attachment #9599374 - Attachment description: WIP: Bug 2021136 - Allow growable SharedArrayBuffer in WebAssembly.Memory structured clone. → Bug 2021136 - Allow growable SharedArrayBuffer in WebAssembly.Memory structured clone.
Attachment #9599375 - Attachment is obsolete: true
Attachment #9551125 - Attachment is obsolete: true
Status: UNCONFIRMED → RESOLVED
Closed: 3 months ago
Resolution: --- → FIXED
Target Milestone: --- → 154 Branch

This is now in Firefox 154 (nightly), but after discussions with the team, it would be good to uplift this into 153 (ESR).

This bug was blocking an external project, emscripten.

firefox-beta Uplift Approval Request

  • User impact if declined/Reason for urgency: toResizableBuffer() was not working with wasm workers. This was an issue for an external project (emscripten).

To avoid them having to use some userAgent probe in the future, it would be good to have this patch in an ESR release.

  • Code covered by automated testing?: yes
  • Fix verified in Nightly?: yes
  • Needs manual QE testing?: no
  • Steps to reproduce for manual QE testing:
  • Risk associated with taking this patch: low
  • Explanation of risk level: Small and contained patch which is updating an old assert to allow the usage of growable wasm SharedArrayBuffers with workers.
  • String changes made/needed?: None
  • Is Android affected?: yes
Attachment #9603199 - Flags: approval-mozilla-beta?
Attachment #9603199 - Flags: approval-mozilla-beta? → approval-mozilla-beta+
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: