Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataCloneError: WebAssembly.Memory object could not be cloned. #5

Closed
AlexErrant opened this issue Nov 5, 2023 · 2 comments · Fixed by #6
Closed

DataCloneError: WebAssembly.Memory object could not be cloned. #5

AlexErrant opened this issue Nov 5, 2023 · 2 comments · Fixed by #6

Comments

@AlexErrant
Copy link
Contributor

AlexErrant commented Nov 5, 2023

I'm very new to Rust so please assume the worst.

Describe the bug
I'm getting WebAssembly.Memory object could not be cloned in Firefox and Chrome on the latest Main and the latest human commit for shared-memory.

separate-memory and separate-memory-transfer work as expected, presumably because they don't use wasm_bindgen::memory() which I assume cannot be cloned.

To Reproduce

I pinned wasm-bindgen to "=0.2.81" here (for both the latest Main and human commit) because otherwise it kept trying to use 0.2.83 - I blame the workspace lock file.

error:

it looks like the Rust project used to create this wasm file was linked against
version of wasm-bindgen that uses a different bindgen format than this binary:

  rust wasm file schema version: 0.2.83
     this binary schema version: 0.2.81

(I've no idea how Nix (flakes) works.) I then ran

cargo install --version 0.2.81 wasm-bindgen-cli --force
cd shared-memory
cargo build --release
wasm-bindgen ../target/wasm32-unknown-unknown/release/shared_memory.wasm --target=no-modules --out-dir=pkg
python ../server.py`

which resulted in the stacktrace at the bottom of this issue.

Expected behavior
No error.

Environment

  • OS name + version: Ubuntu 20.04.4 LTS (really using WSL though)
  • Chrome 119.0.0.0
  • Firefox 119.0

Additional context

I found this potentially relevant SO question, but reading the generated pkg/shared_memory.js file doesn't reveal any new WebAssembly.Memory calls.

Complete stacktrace:

panicked at shared-memory/src/lib.rs:41:6:
failed to start worker 1: JsValue(DataCloneError: WebAssembly.Memory object could not be cloned.
getImports/imports.wbg.__wbg_postMessage_8a8f33d997e17e7b/<@http://localhost:8000/pkg/shared_memory.js:282:25
handleError@http://localhost:8000/pkg/shared_memory.js:201:18
getImports/imports.wbg.__wbg_postMessage_8a8f33d997e17e7b@http://localhost:8000/pkg/shared_memory.js:281:74
web_sys::features::gen_Worker::Worker::post_message::hfc0de0597810731c@http://localhost:8000/pkg/shared_memory_bg.wasm:wasm-function[138]:0x10d01
run@http://localhost:8000/pkg/shared_memory_bg.wasm:wasm-function[22]:0x5938
__exports.run@http://localhost:8000/pkg/shared_memory.js:189:10
promise callback*@http://localhost:8000/index.js:2:45
)

Stack:

getImports/imports.wbg.__wbg_new_abda76e883ba8a5f@http://localhost:8000/pkg/shared_memory.js:256:21
console_error_panic_hook::hook::h2d269cc0da8a6d49@http://localhost:8000/pkg/shared_memory_bg.wasm:wasm-function[50]:0xbcee
core::ops::function::Fn::call::h4825d0fc11fc7cfd@http://localhost:8000/pkg/shared_memory_bg.wasm:wasm-function[246]:0x1196f
std::panicking::rust_panic_with_hook::h3aa054d35a0817d7@http://localhost:8000/pkg/shared_memory_bg.wasm:wasm-function[89]:0xf3ba
std::panicking::begin_panic_handler::{{closure}}::h2f73e4cf6cd6319a@http://localhost:8000/pkg/shared_memory_bg.wasm:wasm-function[105]:0x10075
std::sys_common::backtrace::__rust_end_short_backtrace::h98ac61a6abbff7e9@http://localhost:8000/pkg/shared_memory_bg.wasm:wasm-function[241]:0x11947
rust_begin_unwind@http://localhost:8000/pkg/shared_memory_bg.wasm:wasm-function[123]:0x1088c
core::panicking::panic_fmt::h3e1dd3d08288569e@http://localhost:8000/pkg/shared_memory_bg.wasm:wasm-function[145]:0x10ee4
core::result::unwrap_failed::h8b3db0f11171b57b@http://localhost:8000/pkg/shared_memory_bg.wasm:wasm-function[113]:0x104c7
run@http://localhost:8000/pkg/shared_memory_bg.wasm:wasm-function[22]:0x5c41
__exports.run@http://localhost:8000/pkg/shared_memory.js:189:10
promise callback*@http://localhost:8000/index.js:2:45
@AlexErrant
Copy link
Contributor Author

Ah, I need to use nightly, as mentioned in the blog:

rustup override set nightly
RUSTFLAGS="-C target-feature=+atomics,+bulk-memory,+mutable-globals" cargo build --target=wasm32-unknown-unknown --release -Z build-std=panic_abort,std

After that, shared_memory.js contains

function __wbg_init_memory(imports, maybe_memory) {
    imports.wbg.memory = maybe_memory || new WebAssembly.Memory({initial:18,maximum:16384,shared:true});
}

when previously it contained

function __wbg_init_memory(imports, maybe_memory) {

}

@jneem
Copy link
Member

jneem commented Nov 6, 2023

Thanks for the report! I'll fix the wasm-bindgen version pinning and make the nightly thing clearer in the README.

@AlexErrant AlexErrant mentioned this issue Nov 6, 2023
@jneem jneem closed this as completed in #6 Nov 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants