tonic-web-wasm-client icon indicating copy to clipboard operation
tonic-web-wasm-client copied to clipboard

Cannot perform Construct on a detached ArrayBuffer

Open zvolin opened this issue 9 months ago • 2 comments

Hey and thank you for this cool project :) I've recently caught this error on our CI. It seems like a one-off failure or at least I don't know how to reproduce it, but wanted to report it.

console.log div contained:
    wasm-bindgen: imported JS function that was not marked as `catch` threw an error:
    Cannot perform Construct on a detached ArrayBuffer
    
    Stack:
    TypeError: Cannot perform Construct on a detached ArrayBuffer
        at new Uint8Array (<anonymous>)
        at http://127.0.0.1:45979/wasm-bindgen-test:821:21
        at logError (http://127.0.0.1:45979/wasm-bindgen-test:15:18)
        at imports.wbg.__wbg_new_a12002a7f91c75be (http://127.0.0.1:45979/wasm-bindgen-test:820:66)
        at tonic-0a60b64dc0c378db.wasm.__wbg_new_a12002a7f91c75be externref shim (http://127.0.0.1:45979/wasm-bindgen-test_bg.wasm:wasm-function[11739]:0x3d8547)
        at tonic-0a60b64dc0c378db.wasm.js_sys::Uint8Array::new::hd19c385c5c06e79c (http://127.0.0.1:45979/wasm-bindgen-test_bg.wasm:wasm-function[6907]:0x393fcd)
        at tonic-0a60b64dc0c378db.wasm.<js_sys::Uint8Array as core::convert::From<&[u8]>>::from::hef436ecde67c2879 (http://127.0.0.1:45979/wasm-bindgen-test_bg.wasm:wasm-function[6249]:0x3829b3)
        at tonic-0a60b64dc0c378db.wasm.tonic_web_wasm_client::call::prepare_body::{{closure}}::{{closure}}::h3ef7b83f9a746715 (http://127.0.0.1:45979/wasm-bindgen-test_bg.wasm:wasm-function[6865]:0x392eda)
        at tonic-0a60b64dc0c378db.wasm.core::option::Option<T>::map::h1480b2b09967572e (http://127.0.0.1:45979/wasm-bindgen-test_bg.wasm:wasm-function[3005]:0x2f3d70)
        at tonic-0a60b64dc0c378db.wasm.tonic_web_wasm_client::call::prepare_body::{{closure}}::h60cd4ae367056104 (http://127.0.0.1:45979/wasm-bindgen-test_bg.wasm:wasm-function[846]:0x1e11ef)

zvolin avatar Feb 26 '25 14:02 zvolin

Thanks for reporting this issue @zvolin. Unfortunately, there aren’t enough details in the issue for me to try and reproduce it. Can you attach some more details (like what you're trying to do and some code)?

devashishdxt avatar Mar 18 '25 05:03 devashishdxt

So we have some wrappers around grpc API but I believe the core usage is quite basic and this error doesn't come from our code.

We have a wrapper which is generic over tonic::client::GrpcService and we wrap grpc methods with macro to hide the proto generated types from user. Each such grpc method just instantiates corresponding client by cloning the tonic transport, converting input type to the request, and then converting response. For wasm, we construct it with tonic-web-wasm-client and we use grpcwebproxy as a gateway.

The callstack from the error points to Uint8Array::from inside the call which shouldn't care much about our pre/post input processing, as here it's just BoxBody.

there aren’t enough details in the issue for me to try and reproduce it

The error happened only a single time when running tests with wasm-pack test --chrome --headless. This particular job ran tens if not hundreds of times already and I never seen anything similar, and it failed when there were no changes related to grpc at all, so I have no idea how could you reproduce it unfortunately. It seems to be something that can fail randomly but with very low probability, I have no clue what factors account for that tho

zvolin avatar Mar 19 '25 10:03 zvolin