element-hq / element-hq/element-ios
UIApplication.backgroundTimeRemaining on background thread
- Dominant language
- Swift
- Stars
- 1.8k
- Forks
- 544
- PR merge metrics
- PR metrics pending
Description
`-[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
```
Contributor guide
Research direction
Start at MXUIKitApplicationStateService.backgroundTimeRemaining and trace its callers through MXUIKitBackgroundModeHandler.startBackgroundTaskWithName:expirationHandler: and MXHTTPClient.startBackgroundTask. Reproduce the Main Thread Checker warning on iOS 12.5.1 and compare behavior on iOS 14. Done means the background request path no longer triggers this warning while background-time handling still works.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ios, swift
- Domain
- mobile-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100