KMP-NativeCoroutines icon indicating copy to clipboard operation
KMP-NativeCoroutines copied to clipboard

Priority Inversion Warning After Upgrading to 1.0.0-ALPHA-45

Open VitoNYang opened this issue 3 months ago • 1 comments

Hi @rickclephas , After upgrading from 1.0.0-ALPHA-4 to 1.0.0-ALPHA-45, I occasionally see the following runtime warning in Xcode:

Thread running at User-interactive quality-of-service class waiting on a lower QoS thread running at Default quality-of-service class. 
Investigate ways to avoid priority inversions

This suggests a priority inversion issue, where a high QoS thread (likely UI / main thread) is waiting on a lower QoS thread.

Frequency • Happens occasionally, not consistently reproducible. • I’m not sure under what exact conditions this gets triggered.

Steps to Reproduce Currently uncertain — the issue occurs sporadically and I have not found a stable reproduction path yet.

Could you please help check if this is something that can be fixed in the library, or if I should handle it differently on the app side?

Image

VitoNYang avatar Sep 03 '25 08:09 VitoNYang

Hi!

I’m not sure under what exact conditions this gets triggered.

Based on the location of this warning this seems like expected behaviour.

The internal state of the Swift Publisher is guarded by a DispatchSemaphore (as can be seen in your screenshot). In some cases the Kotlin and Swift threads could try to access the state at the same time, resulting in a short wait on one of the threads.

In this case it looks like Kotlin is producing/consuming values on the main thread while Swift is collecting them on another thread with the default QoS. Are you using custom CoroutineScopes with KMP-NativeCoroutines? Or are you observing Flows from a ViewModel?

rickclephas avatar Sep 03 '25 18:09 rickclephas