React-native Xcode: Thread running at User-interactive qos class waiting on a lower QoS thread (thread inversion)

The Apple App Store is saying my react native mobile app crashes on launch. I don't experience the same in my dev environment, neither in VScode nor in Xcode. When I run the app in Xcode, it compiles and works as expected but I found a message in the console output that indicates a possible thread inversion.

In the provided backtrace, it seems to be related to a WebSocket connection in my React Native app. My app starts at a login page. Once the user enters their credentials they click login and a call is made to the app server which is hosted on Heroku.

I think I should review the code related to the mentioned thread (TID: 1269068) and identify where the -[UIApplication applicationState] is being called.

ChatGPT is suggesting to make sure that this call, and any other UI-related calls, are wrapped within a dispatch to the main thread.

My knowledge of reading the backtrace is limited and i'm unsure how to map the backtrace to my actual javascript code. I've added the backtrace below:

Thread Performance Checker: 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
PID: 78136, TID: 1269068
Backtrace
=================================================================
3   xp1                                 0x0000000100ae679c -[SRRunLoopThread runLoop] + 44
4   xp1                                 0x0000000100ae0cc4 +[NSRunLoop(SRWebSocket) SR_networkRunLoop] + 56
5   xp1                                 0x0000000100ae50cc -[SRProxyConnect _openConnection] + 72
6   xp1                                 0x0000000100ae4584 -[SRProxyConnect _configureProxy] + 916
7   xp1                                 0x0000000100ae3d78 -[SRProxyConnect openNetworkStreamWithCompletion:] + 92
8   xp1                                 0x0000000100ae8530 -[SRWebSocket open] + 624
9   xp1                                 0x0000000100754804 -[RCTReconnectingWebSocket start] + 148
10  xp1                                 0x0000000100742b08 -[RCTPackagerConnection init] + 416
11  xp1                                 0x0000000100742948 __49+[RCTPackagerConnection sharedPackagerConnection]_block_invoke + 36
12  libdispatch.dylib                   0x000000010389993c _dispatch_client_callout + 16
13  libdispatch.dylib                   0x000000010389b3dc _dispatch_once_callout + 84
14  xp1                                 0x00000001007428fc +[RCTPackagerConnection sharedPackagerConnection] + 88
15  xp1                                 0x00000001007d1afc -[RCTDevSettings initialize] + 164
16  xp1                                 0x000000010072df4c -[RCTModuleData _initializeModule] + 96
17  xp1                                 0x000000010072d89c -[RCTModuleData setUpInstanceAndBridge:] + 2168
18  xp1                                 0x000000010072f3b4 -[RCTModuleData instance] + 1168
19  xp1                                 0x00000001006d7074 -[RCTCxxBridge moduleForName:lazilyLoadIfNecessary:] + 712
20  xp1                                 0x00000001007382d4 -[RCTModuleRegistry moduleForName:lazilyLoadIfNecessary:] + 140
21  xp1                                 0x000000010073823c -[RCTModuleRegistry moduleForName:] + 48
22  xp1                                 0x00000001007e2ba8 -[RCTPerfMonitor devMenuItem] + 92
23  xp1                                 0x00000001007e2a74 -[RCTPerfMonitor initialize] + 88
24  xp1                                 0x000000010072df4c -[RCTModuleData _initializeModule] + 96
25  xp1                                 0x000000010072d89c -[RCTModuleData setUpInstanceAndBridge:] + 2168
26  xp1                                 0x000000010072f5ec __25-[RCTModuleData instance]_block_invoke + 44
27  xp1                                 0x0000000100793d20 RCTUnsafeExecuteOnMainQueueSync + 52
28  xp1                                 0x000000010072f254 -[RCTModuleData instance] + 816
29  xp1                                 0x00000001006db97c __49-[RCTCxxBridge _prepareModulesWithDispatchGroup:]_block_invoke + 156
30  libdispatch.dylib                   0x00000001038980f0 _dispatch_call_block_and_release + 24
31  libdispatch.dylib                   0x000000010389993c _dispatch_client_callout + 16
32  libdispatch.dylib                   0x00000001038a96ac _dispatch_main_queue_drain + 1428
33  libdispatch.dylib                   0x00000001038a9108 _dispatch_main_queue_callback_4CF + 40
34  CoreFoundation                      0x00000001803ee1b4 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12
35  CoreFoundation                      0x00000001803e88cc __CFRunLoopRun + 1936
36  CoreFoundation                      0x00000001803e7d28 CFRunLoopRunSpecific + 572
37  GraphicsServices                    0x000000018e7cdbc0 GSEventRunModal + 160
38  UIKitCore                           0x00000001852bafdc -[UIApplication _run] + 868
39  UIKitCore                           0x00000001852bec54 UIApplicationMain + 124
40  xp1                                 0x00000001004172e0 main + 96

I found a message in the console output that indicates a possible thread inversion.

A priority inversion is very unlikely to trigger this sort of crash.

Did App Review give you a crash report? If so, please post it here. See Posting a Crash Report for advice on how to do that.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

@julioBytes Did you happen to get a solution for the issue?

React-native Xcode: Thread running at User-interactive qos class waiting on a lower QoS thread (thread inversion)
 
 
Q