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

Foreign trait / callbacks deadlock #157

Closed jhugman closed 1 week ago

jhugman commented 1 week ago

@tayrevor in reports in Matrix:

I'm having an issue where it seems like calling a method too quickly on a foreign trait hangs indefinitely for older (slower) iOS devices. Essentially, I have a heavy computation that is streaming its best result via the foreign trait so the UI can visualize the computation. At first, the values come in very quickly. On newer phones, this isn't a problem but on older phones the thread hangs at the point where it calls the foreign trait. Inspecting with the XCode debugger after a pause reveals where the thread is stuck. Typically this occurs around 10-30 function calls on my test iPhone 10s with similar symptoms on friend's iPhone 13. Adding a 100ms sleep after the foreign function call to space them out works around the issue

This is in a thread I created with spawn(||{}) so it should already be an OS thread. It's not async in the tokio sense as I'm not using its runtime or the async keyword

The deadlocked thread is the rust background thread that is calling the foreign trait method. There's nothing special about it