jhugman / uniffi-bindgen-react-native

A uniffi bindings generator for calling Rust from react-native
https://jhugman.github.io/uniffi-bindgen-react-native/
Other
50 stars 5 forks source link

AbortController causes crash if called after the future has completed #144

Closed Johennes closed 3 weeks ago

Johennes commented 4 weeks ago

A common use case for AbortController is to cancel async operations that were started via the useEffect hook.

useEffect(() => {
  const controller = new AbortController();

  async function loadLatestEvent() {
    if (!item.isTimelineInitialized()) {
      await item.initTimeline(undefined, undefined, { signal: controller.signal });
    }
    ...
  }

  loadLatestEvent().catch(...);

  return () => {
    controller.abort();
  }
}, [item]);

This appears to cause a crash when the clean-up callback runs after the promise has completed.

Thread 2 Crashed:: com.facebook.react.runtime.JavaScript
0   unomed_mobile.debug.dylib              0x10f28c9d0 ffi_matrix_sdk_base_rust_future_cancel_f32 + 44

The code generated by UBRN should be able to recognise this situation and simply do nothing if the abort signal arrives after the task completed.