Skip to content

fix: lock onmessage to prevent duplicate message handlers#25

Open
jiangheng90 wants to merge 1 commit into
paberr:mainfrom
jiangheng90:main
Open

fix: lock onmessage to prevent duplicate message handlers#25
jiangheng90 wants to merge 1 commit into
paberr:mainfrom
jiangheng90:main

Conversation

@jiangheng90

Copy link
Copy Markdown

Problem

wasm-bindgen's mod.default() sets self.onmessage during init.
When wasmworker uses addEventListener('message', ...) for task dispatch,
both handlers fire. The wasm-bindgen handler cannot parse wasmworker's
message format, causing Cannot read properties of undefined (reading 'length').

Fix

Lock the onmessage setter via Object.defineProperty with a no-op
setter after mod.default() completes. Applied to both WORKER_JS
and WORKER_JS_WITH_PRECOMPILED.

Testing

Verified with 4-worker pool running mixed #[webworker_fn] and
#[webworker_channel_fn] tasks. No errors.

wasm-bindgen registers a message handler during mod.default()
initialization. When using addEventListener for task dispatch,
both handlers fire for every postMessage, causing the wasm-bindgen
handler to fail on wasmworker-format messages.

Lock the onmessage setter via Object.defineProperty after init
so that addEventListener remains the sole message dispatch path.
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 this pull request may close these issues.

1 participant