Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dispatch_group_leave crash in swift

This happens very rarely. Here is the last line of the stack trace:

0  libdispatch.dylib              0x0000000197a85a9c dispatch_group_leave + 48

dispatch_group_leave is called in a complete closure which is invoked like this:

  dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),
                { () -> Void in
                    let query = HKStatisticsCollectionQuery(quantityType: quantityType,
                        quantitySamplePredicate: nil,
                        options: statisticOptions,
                        anchorDate: anchorDate,
                        intervalComponents: interval)
                    query.initialResultsHandler = {

                        complete()

So we dispatch to a background thread, run a HKStatisticsCollectionQuery, and then call a function parameter closure called complete. Inside complete is where the dispatch_group_leave is called and the crash happens.

Any ideas are most appreciated! Thanks!

like image 499
jestro Avatar asked May 27 '15 04:05

jestro


1 Answers

If dispatch_group_leave call isn't balanced with dispatch_group_enter then crash may happen.

like image 78
mustafa Avatar answered Sep 19 '22 10:09

mustafa