Post marked as unsolved
241
Views
We have an issue within our main app and it's quite frustrating as we now can't promote them as planned and first have to figure out a workaround for this issue or wait for a solution.
ARKit Bug:
ARKit causes the dispatch queue(default-qos) to stop working. I have a simple code to simulate this scene. In the official ARKit demo.
https://github.com/titman/arkit-14_2_bug/tree/master/arkit-by-example
When using [CMMotionManager startDeviceMotionUpdatesUsingReferenceFrame:toQueue:withHandler:] method to open sensor monitor, and deviceMotionUpdateInterval setting is 0.04.
print logs use callback block, about 1~15 mins later, CMMotionManager will stop working. This issue will be reproduced with high probability,you need to try multi times.
Once a block occurs, it can never be recovered.
Any suggestions? Thank you very much!
Post marked as solved
104
Views
I've implemented a custom VPN app for macOS (Network Extension, Packet Tunnel Provider).
I got some reports that my app crashed. I asked for the Console logs, and I saw this log:
MyAppExtension[85331]: BUG in libdispatch client: vnode, monitored resource vanished before the source cancel handler was invoked { 0x7f9debe12120[source], ident: 5 / 0x5, handler: 0x107f09ced }
This log appeared multiple times (every couple of hours), each time with a different PID:
MyAppExtension[85765]: BUG in libdispatch client: vnode, monitored resource vanished before the source cancel handler was invoked { 0x7fe76fc1ae70[source], ident: 5 / 0x5, handler: 0x1007d5ced }
Is it what crashed the app? The PID was different each time, so I guess it did crash the app.
What info can I get from this message (how to debug it)?
Post marked as unsolved
280
Views
Hi, I am making a Launch Daemon app in Swift for MacOS. This app needs to make a request to an api once every couple of minutes. I do this using a Timer but I have experienced that on some users machines the timer does not get restarted once the system comes back from sleep. I also have other repeating timers that have the same behaviour so it is not related to just one. When this happens the app does not crash the timers just suddenly stop.
This is the Timer im using:
class RepeatingTimer {
public var timer: DispatchSourceTimer?
init(interval: Int, queue: DispatchQueue, deadline: DispatchTime = .now(), eventHandler: @escaping ()- Void) {
timer = DispatchSource.makeTimerSource(flags: [], queue: queue)
timer?.schedule(deadline: deadline, repeating: .seconds(interval))
timer?.setEventHandler {
eventHandler()
}
}
func start() {
timer?.resume()
}
func stop() {
timer = nil
}
}
I stop the Timers on applicationWillTerminate
Post marked as unsolved
182
Views
So this may be because UserDefaults are getting reset after a period of time, maybe because I update the OS frequently, but a released version of my app after a period of time will crash on my login screen, probably where I check for saved credentials. Reinstalling the app fixes the issue. Console returns a lot of :
Unsupported use of UIKit view-customization API off the main thread. -setAlignsToKeyboard: sent to _UIAlertControllerView: 0x125b2d070; frame = (0 0; 414 896); layer = CALayer: 0x283f652e0
Cannot be called with asCopy = NO on non-main thread.
And my system logs show an error on this thread:
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Triggered by Thread: 4
Application Specific Information:
abort() called
...
Thread 4 name: Dispatch queue: com.apple.NSURLSession-delegate
Thread 4 Crashed:
0 libsystem_kernel.dylib 0x00000001bfb4e414 0x1bfb26000 + 164884
1 libsystem_pthread.dylib 0x00000001dd6a8b50 0x1dd6a6000 + 11088
2 libsystem_c.dylib 0x000000019b027b74 0x19afb1000 + 486260
3 libc++abi.dylib 0x00000001a6d1acf8 0x1a6d07000 + 81144
4 libc++abi.dylib 0x00000001a6d0be4c 0x1a6d07000 + 20044
5 libobjc.A.dylib 0x00000001a6c14f64 0x1a6c0e000 + 28516
6 libc++abi.dylib 0x00000001a6d1a0e0 0x1a6d07000 + 78048
7 libc++abi.dylib 0x00000001a6d1a06c 0x1a6d07000 + 77932
8 libdispatch.dylib 0x00000001917eddc4 0x1917ea000 + 15812
9 libdispatch.dylib 0x00000001917f510c 0x1917ea000 + 45324
10 libdispatch.dylib 0x00000001917f5c90 0x1917ea000 + 48272
11 libdispatch.dylib 0x00000001917ffd78 0x1917ea000 + 89464
12 libsystem_pthread.dylib 0x00000001dd6a9814 0x1dd6a6000 + 14356
13 libsystem_pthread.dylib 0x00000001dd6b076c 0x1dd6a6000 + 42860
Here is some code that I use to check saved credentials. In the backend API I cannot see any login attempts. If it helps, I can see this viewcontroller for a split second right before it crashes. Not sure if that rules out viewdidload.
override func viewDidLoad() {
super.viewDidLoad()
addLoadingSpinner()
bLogIn.titleLabel?.font = UIFont.setToVoiceLight()
self.tfCustomerID.delegate = self
self.tfUsername.delegate = self
self.tfPassword.delegate = self
tfUsername.keyboardType = .default
tfPassword.textContentType = .password
setupUI()
if UserDefaults.standard.string(forKey: UserDefaultsKeys.session) != nil
&& UserDefaults.standard.string(forKey: UserDefaultsKeys.savedCred) == "True" {
login_session = UserDefaults.standard.string(forKey: UserDefaultsKeys.session)!
check_session()
}
else if UserDefaults.standard.string(forKey: UserDefaultsKeys.savedCred) == "True"
&& UserDefaults.standard.string(forKey: UserDefaultsKeys.usesBiometrics) == "True" {
promptTouchOrFaceID()
}
removeLoadingSpinner()
}
override func viewWillAppear(_ animated: Bool) {
AppDelegate.AppUtility.lockOrientation(UIInterfaceOrientationMask.portrait, andRotateTo: UIInterfaceOrientation.portrait)
cbSave.isChecked = UserDefaults.standard.string(forKey: UserDefaultsKeys.savedCred) == "True"
addObservers()
}
func check_session() {
UserDefaults.standard.set(login_session, forKey: "session")
UserInfo.access_token = UserDefaults.standard.string(forKey: "session")!
var request = URLRequest(url: NSURL(string: checksession_url)! as URL)
request.httpMethod = .GET
request.addValues(...)
let task = URLSession.shared.dataTask(with: request) { data, response, error in
if let httpStatus = response as? HTTPURLResponse, httpStatus.statusCode == 200 {
//NEVER GETTING TO API
DispatchQueue.main.async {
...
}
} else {
self.promptTouchOrFaceID()
UserDefaults.standard.set(nil, forKey: UserDefaultsKeys.session)
}
}
task.resume()
}
Thanks in advance for any advice. Finding this to be pretty difficult to solve.
Post marked as solved
119
Views
hello,
i know i could be overly paranoid at times.. but
is this the case that i need to protect my global memory location (that i read from / write to) with read/write memory barriers even if i'm only accessing that location from a single serial DispatchQueue? considering the fact that GCD can pick a different thread to run operations on that queue, and a further fact that different threads can run on different cores and thus have different L1/L2 caches, so that the barrier unprotected write to a location in one code invocation (that runs on my serial queue, that happens to be bound to thread1/core1 at the time) might not yet be visible to a different invocation of my code that runs a bit later on the same serial GCD queue but it so happens that now it runs on thread2/core2, so that the barrier unprotected read from that global memory location returns some stale data?
is the answer any different if we consider a serial (maxConcurrentCount=1) OperationQueue instead of a serial dispatch queue?
finally, is the answer any different if we consider a single NSThread / pthread instead of a serial dispatch queue? can a single thread be bound to different cores during its lifetime? (e.g. work on one core, then sleep, then awake on a different core).
thank you.
Post marked as solved
884
Views
hello,
i don't think it is provided by the system already so i'd like to implement a smart version of DispatchQueue.async function - the one that will not reschedule the block if i am already on the queue in question and call the block directly instead in this case.
extension DispatchQueue {
func asyncSmart(execute: @escaping () -> Void) {
if DispatchQueue.current === self { // ?????
execute()
} else {
async(execute: execute)
}
}
}
the immediate problem is that there is no way to get the current queue (in order to compare it with the queue parameter and do the logic branch).
anyone've been through it and solved this puzzle?
Post marked as unsolved
106
Views
I'm getting crashes in an app affecting hundreds. I use CLLocationManager get location when app launch,Crash happen when app launch。Have you encountered any similar problems and how to solve them? Thank you !!
this crash log:
1 libobjc.A.dylib objc_exception_throw + 56
2 CoreFoundation ___methodDescriptionForSelector
3 CoreFoundation __forwarding_ + 1380
4 CoreFoundation _CF_forwarding_prep_0 + 92
5 GeoServices ___33-[GEOPlatform hardwareIdentifier]_block_invoke + 64
6 libdispatch.dylib __dispatch_client_callout + 16
7 libdispatch.dylib _dispatch_once_f$VARIANT$mp + 60
8 GeoServices -[GEOPlatform hardwareIdentifier] + 56
9 GeoServices -[GEOPDAnalyticMetadata(PlaceDataExtras) initWithTraits:] + 456
10 GeoServices -[GEOPDPlaceRequest(PlaceDataExtras) _initWithTraits:] + 124
11 GeoServices -[GEOPDPlaceRequest(PlaceDataExtras) initWithTraits:count:includeEntryPoints:] + 68
12 GeoServices -[GEOPDPlaceRequest(PlaceDataExtras) initWithReverseGeocodeCoordinate:includeEntryPoints:preserveOriginalLocation:traits:] + 60
13 GeoServices -[GEOMapService _searchable_ticketForReverseGeocodeCoordinate:includeEntryPoints:shiftLocationsIfNeeded:preserveOriginalLocation:traits:] + 116
14 GeoServices -[GEOMapService ticketForReverseGeocodeCoordinate:includeEntryPoints:shiftLocationsIfNeeded:preserveOriginalLocation:traits:] + 140
15 GeoServices -[GEOMapService ticketForReverseGeocodeCoordinate:includeEntryPoints:shiftLocationsIfNeeded:traits:] + 108
16 GeoServices -[GEOMapService _cl_ticketForReverseGeocodeLocation:traits:] + 200
17 CoreLocation CLClientCreateIso6709Notation + 37032
18 libdispatch.dylib __dispatch_call_block_and_release + 24
19 libdispatch.dylib __dispatch_client_callout + 16
20 libdispatch.dylib __dispatch_queue_serial_drain$VARIANT$mp + 528
21 libdispatch.dylib __dispatch_queue_invoke$VARIANT$mp + 340
22 libdispatch.dylib __dispatch_root_queue_drain_deferred_wlh$VARIANT$mp + 404
23 libdispatch.dylib __dispatch_workloop_worker_thread$VARIANT$mp + 644
24 libsystem_pthread.dylib _pthread_wqthread + 932
25 libsystem_pthread.dylib start_wqthread + 4
Post marked as unsolved
99
Views
mKay, I want to spin off say 4 heavy CPU worker threads on a Mac Mini M1. Perhaps naaiive of me, but don't I want to put as many of the threads on the high-power processors? Is there some way to request a preference for those? Or is it first-come first-served? The documentation seems mighty slim on this subject.
Using posix threads, and they work just fine, just would like a little more control. Hoping the answer is not "Mach tries to be as cpu-independent as possible so that kind of option is not going to be implemented".
Post marked as solved
102
Views
How can I implement a NSProgressIndicator in a non void function?
This is not supported in a non void function, what can I do?
dispatchasync( dispatchgetglobalqueue(DISPATCHQUEUEPRIORITYDEFAULT, 0),
dispatchasync(dispatchgetmain_queue(), ^{
[myProgressBar setUsesThreadedAnimation:YES];
[myProgressBar setHidden:FALSE];
[myProgressBar setDoubleValue:15.0];
[myProgressBar startAnimation:myProgressBar];
});
});
any help is very appreciated.
Post marked as unsolved
247
Views
Hi guys,
I hope you are doing fine.
I am trying to achieve following thing:
) Fetch data array from database (async call)
) Iterate over fetched data array
) Fetch additional information about each object (async call)
) Create a new data array with all the information and return it back
Currently, I have following approach
self.dataAccessService.fetchRepliesByCommentId(completionHandler: { (commentReplyArray) in
for var i in 0..<commentReplyArray.count {
let commentReply = commentReplyArray[i]
let commentItem = CommentItem()
self.fetchDetailsAboutCommentReply(commentReplyObject: commentReply) { (commentItem) in
commentItem.commentObject = commentReply
dataSource.insert(commentItem, at: index + i + 1) -> APP CRASHES HERE, i is never 0 here
ips.append(IndexPath(row: index + i + 1 , section: 0))
if (i == commentReplyArray.count - 1) {
self.delegate?.didLoadReplies(dataSource: dataSource, ips: ips)
}
}
}
}, commentId: commentItem.commentObject.id)
My fetchDetailsAboutCommentReply function:
private func fetchDetailsAboutCommentReply(commentReplyObject:CommentReply, completionHandler:@escaping(CommentItem)->()) {
let group = DispatchGroup()
let commentItem = CommentItem()
group.enter()
self.dataAccessService.fetchUserById(completionHandler: { (userObject) in
commentItem.userObject = userObject
group.leave()
}, uid: commentReplyObject.userId)
group.enter()
self.dataAccessService.fetchDownloadURLOfProfileImage(organizerId: commentReplyObject.userId) { (contentURL) in
commentItem.userObject.contentURL = contentURL
group.leave()
}
group.notify(queue: .main) {
completionHandler(commentItem)
}
}
My question is how, I can change my code, so the loop basically "pauses" until I fetch every detail information of the iterated object, add it into the dataSource Array and then continues with the next one?
Thanks and stay healthy!
Post marked as unsolved
159
Views
After a while of using my application, the DispatchQueue Default-QoS stops picking up workloads. I can see them getting queued and everything else in the application is working. This only started happening in iOS 14.1+
Post marked as unsolved
501
Views
I have received this report through firebase analytics(Crashlytics) and I have no idea what it is. Would you help me?
The problem is only in iOS 14. (iOS 14.0.0, 14.2.0)
There is no such case in versions below iOS 14
crash_info_entry_0
BUG IN CLIENT OF LIBDISPATCH: Unbalanced call to dispatch_group_leave()
Stack trace
Crashed: Thread #1
EXCBREAKPOINT 0x000000019836f7f4
Crashed: Thread
0 libdispatch.dylib 0x19836f7f4 <redacted> + 36
1 libdispatch.dylib 0x19833d8c4 dispatchgroupleave + 126
2 ??? 0x754b330102689c00 (Missing)
3 Life4MePlus 0x102682b8c -[AISynchronizationOperation main] + 38 (AISynchronizationOperation.m:38)
4 Foundation 0x199a9c0f0 <redacted> + 864
5 ??? 0x0 (Missing)
6 ??? 0x221c4e81dfc97800 (Missing)
com.apple.main-thread
com.apple.main-thread
0 libsystemkernel.dylib 0x1c4643dd0 machmsgtrap + 8
1 libsystemkernel.dylib 0x1c4643184 machmsg + 76
2 ??? 0x4b112781986bac00 (Missing)
3 ??? 0x31204581986b4e00 (Missing)
4 ??? 0x0 (Missing)
5 ??? 0x0 (Missing)
6 ??? 0x0 (Missing)
7 ??? 0x0 (Missing)
8 ??? 0x0 (Missing)
9 libdyld.dylib 0x19837be60 <redacted> + 4
Thread #2
Thread
0 libsystemkernel.dylib 0x1c46685bc workqkernreturn + 8
1 libsystempthread.dylib 0x1dfc90954 pthreadwqthread + 352
2 ??? 0x5d3bd101dfc97800 (Missing)
Thread #3
Thread
0 libsystemkernel.dylib 0x1c46685bc _workqkernreturn + 8
1 libsystempthread.dylib 0x1dfc90954 pthreadwqthread + 352
2 ??? 0x0 (Missing)
Thread #4
Thread
0 libsystemkernel.dylib 0x1c46685bc _workqkernreturn + 8
1 libsystempthread.dylib 0x1dfc90954 pthreadwqthread + 352
2 ??? 0x3453b581dfc97800 (Missing)
com.apple.uikit.eventfetch-thread
com.apple.uikit.eventfetch-thread
0 libsystemkernel.dylib 0x1c4643dd0 machmsgtrap + 8
1 libsystemkernel.dylib 0x1c4643184 machmsg + 76
2 ??? 0x0 (Missing)
3 ??? 0x61681c01986b5000 (Missing)
4 ??? 0x0 (Missing)
5 ??? 0x0 (Missing)
6 ??? 0x0 (Missing)
7 ??? 0x4a214b819b109000 (Missing)
8 ??? 0x15469a8199a9c100 (Missing)
9 ??? 0x0 (Missing)
10 ??? 0x0 (Missing)
Thread #5
Thread
0 libsystemkernel.dylib 0x1c46685bc workqkernreturn + 8
1 libsystempthread.dylib 0x1dfc90954 pthreadwqthread + 352
2 ??? 0x0 (Missing)
Thread #6
Thread
0 libsystemkernel.dylib 0x1c46685bc _workqkernreturn + 8
1 libsystempthread.dylib 0x1dfc90954 pthreadwqthread + 352
2 ??? 0x0 (Missing)
Thread #7
Thread
0 libsystemkernel.dylib 0x1c46685bc _workqkernreturn + 8
1 libsystempthread.dylib 0x1dfc90954 pthreadwqthread + 352
2 ??? 0x0 (Missing)
com.twitter.crashlytics.ios.MachExceptionServer
com.twitter.crashlytics.ios.MachExceptionServer
0 Life4MePlus 0x10277e5dc CLSProcessRecordAllThreads + 376 (CLSProcess.c:376)
1 Life4MePlus 0x10277e5dc CLSProcessRecordAllThreads + 376 (CLSProcess.c:376)
2 Life4MePlus 0x10277ea50 CLSProcessRecordAllThreads + 407 (CLSProcess.c:407)
3 Life4MePlus 0x10276ee60 CLSHandler + 26 (CLSHandler.m:26)
4 Life4MePlus 0x10276a204 CLSMachExceptionServer + 446 (CLSMachException.c:446)
5 libsystempthread.dylib 0x1dfc8eca8 pthreadstart + 320
6 ??? 0x7c25b581dfc97800 (Missing)
AFRKNetworking
AFRKNetworking
0 libsystemkernel.dylib 0x1c4643dd0 machmsgtrap + 8
1 libsystemkernel.dylib 0x1c4643184 machmsg + 76
2 ??? 0x3713a981986bac00 (Missing)
3 ??? 0x0 (Missing)
4 ??? 0x684cc081986b4400 (Missing)
5 ??? 0x7237968199932000 (Missing)
6 ??? 0x6813c40199964800 (Missing)
7 ??? 0x452e2b010368f800 (Missing)
8 Foundation 0x199a9c0f0 <redacted> + 864
9 ??? 0x0 (Missing)
10 ??? 0x710e8a81dfc97800 (Missing)
Thread #8
Thread
0 libsystempthread.dylib 0x1dfc97774 <redacted> + 6
com.apple.NSURLConnectionLoader
com.apple.NSURLConnectionLoader
0 libsystemkernel.dylib 0x1c4643dd0 machmsgtrap + 8
1 libsystemkernel.dylib 0x1c4643184 mach_msg + 76
2 ??? 0x0 (Missing)
3 ??? 0x0 (Missing)
4 ??? 0x60677381986b4400 (Missing)
5 ??? 0x386bc00198f6d000 (Missing)
6 ??? 0x552580199a9c100 (Missing)
7 ??? 0x47378301dfc8ec00 (Missing)
8 ??? 0x0 (Missing)
Post marked as unsolved
145
Views
Do I need to release the block which passed to the dispatchbarrierasync when no ARC ? I noticed "The barrier block to submit to the target dispatch queue. This block is copied and retained until it finishes executing, at which point it is released." in dispatchbarrierasync.dispatch_block_t work = dispatch_block_create(0, ^{
//...
});
if (work) {
dispatchbarrierasync(dispatchQueue, work);
auto res = dispatchblockwait(work, timeout);
if (res) {
// timeout, then cancel, I should release work here?
dispatchblockcancel(work);
}
Blockrelease(work); // do I need to release work when no ARC? the dispatchbarrierasync would release it if it's executed?
}
}
Thanks!
Post marked as unsolved
119
Views
My girlfriend told me today, NSOperationQueue is awesome, the bottom layer must be encapsulated GCDS.
I said, NSOperationQueue came out before GCD, so how do you wrap a GCD? The GCD came out around 2011.
We ended up fighting about it.
Can someone help me explain? thank you
Post marked as unsolved
184
Views
HI,
I’m just learning Swift and was looking at Grand Central Dispatch (GCD) for some CPU intensive tasks. Here are (I believe) all the relevant bits of code I’m puzzled by:
// global declarations
var digits = [Int]() // where the square's digits reside
var perm_q = [[Int]]() // where we accumulate permutations to check later
Let perm_q_max = 1000 // how many permutations we queue before checking them
var enq_count = 0 // how many times we've called check_squares
var N = 3 // size of N x N square
let work_q = DispatchQueue.global() // returns a global, concurrent dispatch queue
let work_g = DispatchGroup() // returns a group we put all our work into
// func which is enqueued onto a GCD queue
func check_squares( cnt: Int, perm_ary: [[Int]]) { ... }
// func which enqueues check_squares() onto global GCD queue
func permute( k: Int, ary: inout [Int]) {
if k == 1 {
perm_q.append( ary) // queue up this permutation for later magic checking
// if we've queued up enough permutations, then dispatch check_squares()
if ( perm_q.count >= perm_q_max) {
enq_count += 1
// --> let p: [[Int]] = perm_q // make a local copy
work_q.async( group: work_g) { // assign work all to one group
check_squares( cnt: enq_count, // check to see if any square is magic
perm_ary: p)
}
perm_q = [[Int]]() // clear out previous permutations
}
}
else { ... }
}
// main
// Create a dispatch queue onto which we'll put the square-checking tasks.
digits = Array( 1 ... ( N * N)) // fill digits with digits 1...N^2
permute( k: digits.count, ary: &digits) // creates permutations and checks for magic squares
The problem I’m having is that unless I uncomment the line just above work\_q.async() in permute(), when check\_squares() starts, ary has zero elements when I expect it to have 1,000 elements. Right after I enqueue check\_squares() to GCD on the global async queue, I do perm\_q = [[Int]]() which empties array perm\_q to be ready to collect the next 1,000 elements.
I’m guessing there is a race condition between starting check\_squares() and emptying perm\_q, and the emptying occurs before check\_squares() starts, but I’m puzzled as to why this race occurs. I understood that the call to check\_squares() would make a copy of perm\_q, and I thought this copy would happen with the call to check\_squares().
One explanation I thought of is that the copy of perm\_q into check\_squares()’s param ary doesn’t happen until GCD starts to execute check\_squres(). By the time this happens, perm\_q has been emptied. Is that when the copy of perm\_q into ary happens and not when check\_squares() is enqueued? Making the local copy of global var perm\_q into var p local to permute() and passing p to check\_squares() during the enqueue makes local var p stick around since the reference from check\_squares() in the queue keeps array p from disappearing even after permute() exits. Does this sound right?
Other than making the local copy of perm\_q into p, is there a preferred method of handing this?
Thanks, Eric