element-hq / element-ios

A glossy Matrix collaboration client for iOS
https://element.io
GNU Affero General Public License v3.0
1.73k stars 498 forks source link

UIApplication.backgroundTimeRemaining on background thread #3996

Open ismailgulek opened 3 years ago

ismailgulek commented 3 years ago

-[UIApplication backgroundTimeRemaining] complaints about being called on non-main thread, although method documentation says:

This method can be safely called on a non-main thread.

Seen on iOS 12.5.1. On iOS 14, it seems fine.

Main Thread Checker: UI API called on a background thread: -[UIApplication backgroundTimeRemaining]
PID: 814, TID: 68649, Thread name: (none), Queue name: MXCrypto-@ismailgulekmac3:matrix.org, QoS: 0
Backtrace:
4   MatrixSDK                           0x000000010339bed0 $s9MatrixSDK30MXUIKitApplicationStateServiceC23backgroundTimeRemainingSdvg + 68
5   MatrixSDK                           0x000000010339be68 $s9MatrixSDK30MXUIKitApplicationStateServiceC23backgroundTimeRemainingSdvgTo + 32
6   MatrixSDK                           0x000000010330da60 -[MXUIKitBackgroundModeHandler startBackgroundTaskWithName:expirationHandler:] + 404
7   MatrixSDK                           0x000000010315fd60 -[MXHTTPClient startBackgroundTask] + 440
8   MatrixSDK                           0x000000010315c478 -[MXHTTPClient tryRequest:method:path:parameters:data:headers:timeout:uploadProgress:success:failure:] + 2124
9   MatrixSDK                           0x000000010315a484 -[MXHTTPClient requestWithMethod:path:parameters:data:headers:timeout:uploadProgress:success:failure:] + 420
10  MatrixSDK                           0x000000010315a27c -[MXHTTPClient requestWithMethod:path:parameters:timeout:success:failure:] + 268
11  MatrixSDK                           0x000000010315a10c -[MXHTTPClient requestWithMethod:path:parameters:success:failure:] + 224
12  MatrixSDK                           0x000000010327c3c8 -[MXRestClient uploadKeys:oneTimeKeys:success:failure:] + 660
13  MatrixSDK                           0x00000001031187b4 -[MXCrypto publishedOneTimeKeysCount:failure:] + 352
14  MatrixSDK                           0x0000000103116fd0 -[MXCrypto maybeUploadOneTimeKeys:failure:] + 1116
15  MatrixSDK                           0x00000001031003d4 __26-[MXCrypto start:failure:]_block_invoke.82 + 516
16  MatrixSDK                           0x000000010327c910 __55-[MXRestClient uploadKeys:oneTimeKeys:success:failure:]_block_invoke_3 + 48
17  MatrixSDK                           0x000000010328c570 __49-[MXRestClient dispatchProcessing:andCompletion:]_block_invoke_2 + 36
18  libdispatch.dylib                   0x0000000106ccf6f4 _dispatch_call_block_and_release + 24
19  libdispatch.dylib                   0x0000000106cd0c78 _dispatch_client_callout + 16
20  libdispatch.dylib                   0x0000000106cd8bf4 _dispatch_lane_serial_drain + 712
21  libdispatch.dylib                   0x0000000106cd98b4 _dispatch_lane_invoke + 456
22  libdispatch.dylib                   0x0000000106ce377c _dispatch_workloop_worker_thread + 1148
23  libsystem_pthread.dylib             0x00000001a4aee114 _pthread_wqthread + 304
24  libsystem_pthread.dylib             0x00000001a4af0cd4 start_wqthread + 4
ismailgulek commented 3 years ago

After further investigation, this seems affecting only iOS 12 devices.