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

Fix detached ArrayBuffer errors #153

Merged
merged 1 commit into from
Jan 25, 2022

Conversation

yonihemi
Copy link
Member

Fixes a regression caused by #150:
Unhandled Promise Rejection: TypeError: Underlying ArrayBuffer has been detached from the view (Safari)
TypeError: Cannot perform %TypedArray%.prototype.set on a detached ArrayBuffer (Chrome)

It's troubling our unit test don't catch this but with my limited knowledge of JS memory management I don't know how to reliably recreate it.

@yonihemi yonihemi requested a review from a team January 25, 2022 06:24
@kateinoigakukun
Copy link
Member

Good catch! As far as I understand, WebAssembly.Memory detaches its internal ArrayBuffer when memory.grow instruction is executed because ArrayBuffer is a fixed-size array. So we need to access WebAssembly.Memory.buffer every time.

@kateinoigakukun
Copy link
Member

Could you add a test case to kill this bug by using __builtin_wasm_memory_grow?

@yonihemi yonihemi merged commit 16eaaa4 into swiftwasm:main Jan 25, 2022
@yonihemi yonihemi deleted the fix/detached_buffer branch January 25, 2022 06:41
@yonihemi
Copy link
Member Author

Good catch! As far as I understand, WebAssembly.Memory detaches its internal ArrayBuffer when memory.grow instruction is executed because ArrayBuffer is a fixed-size array. So we need to access WebAssembly.Memory.buffer every time.

In my case there is no explicit call to .grow anywhere, perhaps it's detached in more cases.

@tierracero
Copy link

tierracero commented Dec 11, 2022

hey hi

hope your all doing fine

seems I got the same error

JavascriptKit 0.17.0

app.js:139 TypeError: Cannot perform DataView.prototype.setBigUint64 on a detached ArrayBuffer
at DataView.setBigUint64 ()
at clock_res_get (index.esm.js:114:167)
at __wasi_clock_res_get (1ddb7b2a:0x3b79363)
at clock_getres (1ddb7b2a:0x3b767a8)
at __CFDateInitialize (1ddb7b2a:0x2ff76e7)
at __CFInitialize (1ddb7b2a:0x2fb8851)
at __wasm_call_ctors (1ddb7b2a:0x76f37)
at _initialize (1ddb7b2a:0x76f56)
at startWasiTask (app.js:133:26)

@j-f1
Copy link
Member

j-f1 commented Dec 11, 2022

Can you open a new issue, and (if you’re able to) provide a code sample that reproduces the error?

@tierracero
Copy link

sure give a min, thank you.

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.

4 participants