After switching to Xcode 14 beta I got this error: QOS_CLASS_USER_INITIATED waiting on a lower QoS thread running at QOS_CLASS_DEFAULT
Asked Answered
E

5

42

My app is working well and I didn't get this error on Xcode 13.4, Is it Xcode 14 beta bug or I'm doing some bad threading?!

Thread running at QOS_CLASS_USER_INITIATED waiting on a lower QoS thread running at QOS_CLASS_DEFAULT. Investigate ways to avoid priority inversions

QOS_CLASS_USER_INITIATED waiting on a lower QoS thread running at QOS_CLASS_DEFAULT.

I didn't understand the issue, so I added my stack log too:

_TtGC7SwiftUI14_UIHostingViewVVS_P10$1dc8d4d8821BridgedNavigationView8RootView_ implements focusItemsInRect: - caching for linear focus movement is limited as long as this view is on screen.
2022-06-07 18:53:41.412342+0430 MyApp[916:25641] [UIFocus] _TtCC7SwiftUI17HostingScrollView22PlatformGroupContainer implements focusItemsInRect: - caching for linear focus movement is limited as long as this view is on screen.
Thread Performance Checker: Thread running at QOS_CLASS_USER_INITIATED waiting on a lower QoS thread running at QOS_CLASS_DEFAULT. Investigate ways to avoid priority inversionsPID: 916, TID: 25815
Backtrace
=================================================================
3   MyApp                                 0x0000000102c7665c -[_FSRRunLoopThread runLoop] + 44
4   MyApp                                 0x0000000102c763a8 __45+[NSRunLoop(FSRWebSocket) FSR_networkRunLoop]_block_invoke + 124
5   libdispatch.dylib                   0x00000001054318fc _dispatch_client_callout + 16
6   libdispatch.dylib                   0x0000000105433240 _dispatch_once_callout + 80
7   MyApp                                 0x0000000102c76304 +[NSRunLoop(FSRWebSocket) FSR_networkRunLoop] + 84
8   MyApp                                 0x0000000102c6ff30 -[FSRWebSocket _connect] + 68
9   MyApp                                 0x0000000102c6ed60 -[FSRWebSocket open] + 216
10  MyApp                                 0x0000000102c4ebdc -[FWebSocketConnection open] + 248
11  MyApp                                 0x0000000102c4d3c4 -[FConnection open] + 112
12  MyApp                                 0x0000000102bf1404 -[FPersistentConnection openNetworkConnectionWithContext:] + 588
13  MyApp                                 0x0000000102bf1078 __45-[FPersistentConnection tryScheduleReconnect]_block_invoke_2 + 332
14  MyApp                                 0x0000000102c3d0fc -[FIRDatabaseConnectionContextProvider fetchContextForcingRefresh:withCallback:] + 264
15  MyApp                                 0x0000000102bf0f0c __45-[FPersistentConnection tryScheduleReconnect]_block_invoke + 460
16  MyApp                                 0x0000000102c1c0d8 -[FIRRetryHelperTask execute] + 92
17  MyApp                                 0x0000000102c1c6dc __24-[FIRRetryHelper retry:]_block_invoke + 84
18  libdispatch.dylib                   0x00000001054300c4 _dispatch_call_block_and_release + 24
19  libdispatch.dylib                   0x00000001054318fc _dispatch_client_callout + 16
20  libdispatch.dylib                   0x0000000105438a58 _dispatch_lane_serial_drain + 688
21  libdispatch.dylib                   0x00000001054396d0 _dispatch_lane_invoke + 424
22  libdispatch.dylib                   0x0000000105445150 _dispatch_workloop_worker_thread + 696
23  libsystem_pthread.dylib             0x000000023db94ddc _pthread_wqthread + 284
24  libsystem_pthread.dylib             0x000000023db94908 start_wqthread + 8
Electrify answered 7/6, 2022 at 14:32 Comment(2)
Seems like it's Firebase related issue.Electrify
Waiting in accessor to run-loop? this really looks strange - needed MRE to debug.Edgeways
D
11

You're getting this message due to a priority inversion in your code. More details here: https://developer.apple.com/documentation/xcode/diagnosing-performance-issues-early

More specifically, you're using dispatch_group_wait which doesn't provide priority inversion avoidance; so your waiting thread is susceptible to an inversion. Seemingly that's what's happening here.

Decerebrate answered 8/6, 2022 at 23:23 Comment(2)
It was running perfect then i updated to new Xcode. Please help how to solve this error.Thrall
@SheikhWahabMahmood actually the code had the issue before, it just wasn't something Xcode detected. This is a new detection in Xcode 14.Teakwood
G
8

More information will help to understand this better but... It looks like you are calling a FireBase class from a thread with a higher QOS than the one used by the class itself.

As Apple wrote in the Diagnosing performance issues early "If you use concurrency primitives, such as dispatch_semaphore_wait and dispatch_group_wait, in your code or invoke APIs that use them, your app is susceptible to priority inversions if there is a mismatch in the quality-of-service (QoS) class of the dispatch queues your app uses."

In your case, you are calling the class from "QOS_CLASS_USER_INITIATED" It is better to fully understand where you are calling it and why.

Since you do not have access to FireBase, you can try to resolve this issue by handling the QOS from the calling site like this:

let backgroundQueue = DispatchQueue(label: "background_queue",
                                            qos: .background)
        
backgroundQueue.async {[weak self] in
    // Call the class you need here and it will be done on a background QOS
}
Gentlefolk answered 2/4, 2023 at 9:7 Comment(0)
P
2

For those coming here because they got the error in their own code, and not in Firebase, Firebase fixed the issue in version 9.6 by adding the line

networkThread.qualityOfService = NSQualityOfServiceUserInitiated;

when they created the thread. Presumably this increases the priority of the network thread so that it will avoid the priority inversion.

Prowess answered 5/4, 2023 at 6:39 Comment(0)
B
0

To disable it, choose Product > Scheme > Edit Scheme to display the scheme editor.

enter image description here

Bouldin answered 18/6 at 19:33 Comment(0)
V
-5

this a bug in Xcode that's mistakenly triggering warnings to be printed. This is not something that we can fix at the moment. Do bear in mind that these warnings are being sent mistakenly; the performance of your app will not be affected.

Vanmeter answered 23/2, 2023 at 9:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.