{"id":100,"date":"2013-06-10T20:35:48","date_gmt":"2013-06-11T02:35:48","guid":{"rendered":"http:\/\/dev.iachieved.it\/iachievedit\/?p=100"},"modified":"2013-06-10T20:35:48","modified_gmt":"2013-06-11T02:35:48","slug":"a-pesky-cocoa-lumberjack-bug","status":"publish","type":"post","link":"https:\/\/dev.iachieved.it\/iachievedit\/a-pesky-cocoa-lumberjack-bug\/","title":{"rendered":"A Pesky Cocoa Lumberjack Bug"},"content":{"rendered":"<p>The latest release of iOS 6 has &#8220;introduced&#8221; a pesky Cocoa Lumberjack bug.  If you recall, Lumberjack is our favorite enhanced logging API for use with iPhone development.  If you don&#8217;t recall, well&#8230; Lumberjack is our favorite enhanced logging API for use with iPhone development.<\/p>\n<p>If you&#8217;ve done any web service development you may be familiar with the technique of starting a query on a asynchronous thread, like this:<\/p>\n<p>[objc]<br \/>\ndispatch_queue_t reattemptQueue = dispatch_queue_create(&quot;reattempt&quot;, NULL);<br \/>\n  dispatch_async(reattemptQueue, ^{<br \/>\n    [self reattemptLogin];<br \/>\n  });<br \/>\n[\/objc]<\/p>\n<p>In short, we&#8217;re trying to log in to a service and the initial attempt failed, so we&#8217;ll create a GCD queue called <em>reattempt<\/em> and then dispatch the call <code>[self reattemptLogin];<\/code> on that queue.  Our <code>[self reattemptLogin]<\/code> code does the following:<\/p>\n<p>[objc]<br \/>\n-(void)reattemptLogin {<br \/>\n  ENTRY_LOG;<br \/>\n[\/objc]<\/p>\n<p>and that&#8217;s really all we have to show you because, boom, it crashes right there!  The error you will mostly see is <code>EXC_BREAKPOINT<\/code> against the code<\/p>\n<p>[objc]<br \/>\ndispatch_queue_t currentQueue = dispatch_get_current_queue();<br \/>\n[\/objc]<\/p>\n<p>inside the Lumberjack source.  Here&#8217;s the break where the exception was generated:<br \/>\n<a href=\"http:\/\/dev.iachieved.it\/iachievedit\/wp-content\/uploads\/2013\/06\/crash.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/dev.iachieved.it\/iachievedit\/wp-content\/uploads\/2013\/06\/crash.png\" alt=\"crash\" width=\"1019\" height=\"163\" class=\"alignnone size-full wp-image-105\" \/><\/a><\/p>\n<p>And here is the crash traceback.<\/p>\n<p><a href=\"http:\/\/dev.iachieved.it\/iachievedit\/wp-content\/uploads\/2013\/06\/crashtrace.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/dev.iachieved.it\/iachievedit\/wp-content\/uploads\/2013\/06\/crashtrace.png\" alt=\"crashtrace\" width=\"504\" height=\"108\" class=\"alignnone size-full wp-image-106\" \/><\/a><\/p>\n<p>There is actually a ticket opened in <a href=\"https:\/\/github.com\/robbiehanson\/CocoaLumberjack\/issues\/108\">Github<\/a> for this issue.  As hinted at by the ticket, the workaround here is to, rather than create a new queue, get the global queue:<\/p>\n<p>[objc]<br \/>\n  dispatch_queue_t reattemptQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);<br \/>\n[\/objc]<\/p>\n<p>Your application can still successfully dispatch an operation to a queue and not block the UI thread, but this time it won&#8217;t crash if you are doing logging.  <\/p>\n<p>What you may find is that your application works fine in a release mode since there is no logging with Lumberjack, but when you start your debug builds up again things start crashing for no apparent reason!  Take a look and see if you are creating named queues with <code>dispatch_queue_create<\/code> and replace it with <code>dispatch_get_global_queue<\/code>!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The latest release of iOS 6 has &#8220;introduced&#8221; a pesky Cocoa Lumberjack bug. If you recall, Lumberjack is our favorite enhanced logging API for use with iPhone development. If you don&#8217;t recall, well&#8230; Lumberjack is our favorite enhanced logging API for use with iPhone development. If you&#8217;ve done any web service development you may be [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-100","post","type-post","status-publish","format-standard","hentry","category-xcodetips"],"_links":{"self":[{"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/posts\/100"}],"collection":[{"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/comments?post=100"}],"version-history":[{"count":8,"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/posts\/100\/revisions"}],"predecessor-version":[{"id":110,"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/posts\/100\/revisions\/110"}],"wp:attachment":[{"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/media?parent=100"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/categories?post=100"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.iachieved.it\/iachievedit\/wp-json\/wp\/v2\/tags?post=100"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}