12

Since moving to iOS 8.3, I'm encountering this error where the main thread will get stuck in this call. A few other threads are also stuck in that call. There is none of my code in any thread that leads to this call, so I'm stumped as to why this is happening. It happens randomly, sometimes, when tapping a button bar item, sometimes while redrawing charts (using ShinobiCharts), etc.

Here is the stack trace from Xcode:

enter image description here

Anybody has any clue as to why this is happening and how to fix it? It's very annoying because when I get stuck there, I have to relaunch the app. Note that this is happening in the simulator so far. I'm in the early stage of developing this app and spend most of my time in the simulator. I haven't seen the error happening yet on a real device but, again, I haven't run the app that often on the device.

nemesys
  • 554
  • 5
  • 14
  • In lldb pause when you encounter this thread lock and type `bt all` in the debugger to show the full memory stack and post the log here. – JAL Jun 02 '15 at 01:51
  • I am facing the same issue.. @nemesys have you found any solution – Steve Gear Jun 02 '15 at 09:18
  • @JAL Will do once it happens again. Like I said before, I haven't been able to reliably reproduce it, so it may be a while before I have the traces. – Shalmezad Jun 02 '15 at 13:24
  • https://gist.github.com/Shalmezad/65ff89d20aa7e0a9d094 If you manage to find something, a quick explanation on how you found it would be greatly appreciated as well. – Shalmezad Jun 02 '15 at 13:41
  • I haven't found anything yet :-( – nemesys Jun 03 '15 at 02:49
  • @SteveGear or nemesys , are either of you using MagicalRecord, AFNetworking, or some form of asynchronous code? (like a typical background GCD block: http://jeffreysambells.com/2013/03/01/asynchronous-operations-in-ios-with-grand-central-dispatch ). – Shalmezad Jun 03 '15 at 13:18
  • Got it to happen again, this time did "View Process By Queue": http://i.imgur.com/1G8UjbA.png If anyone looking at this question needs more information, please let me know. – Shalmezad Jun 03 '15 at 14:57
  • 1
    @Shalmezad I think we are facing the same issue. Please see this thread http://stackoverflow.com/questions/30269243/application-sticks-on-osspinlocklockslow – Peter Zhou Jun 03 '15 at 21:29
  • @nemesys I think we are facing the same issue. http://stackoverflow.com/questions/30269243/application-sticks-on-osspinlocklockslow – Peter Zhou Jun 03 '15 at 21:30
  • @PeterZhou As I noted in my answer below, it appears to be the same based on the stack trace (OSSpinLockLockSlow calls syscall_thread_switch, which can be seen in the backtrace). Changing how my code handled background tasks did eliminate it so far. – Shalmezad Jun 04 '15 at 15:51

1 Answers1

5

Knock on wood, but I think I figured it out (at least in my instance).

What led to the solution was a search for syscall_thread_switch, which led me to this answer here: https://stackoverflow.com/a/30333203/978509

Which, if you look at the backtrace I linked (https://gist.github.com/Shalmezad/65ff89d20aa7e0a9d094), every syscall_thread_switch is preceded by OSSpinLockLockSlow, which the answer notes looks like Livelock, but due to the low CPU usage, is more evident of a deadlock.

Going through my code, I found that for every background task, I created a new dispatch_queue_t each time. I since redid how that works to use the same queue, which seems to have fixed the issue.

Without further information from nemesis (mainly some code snippets showing how he's setting up background tasks), I cannot answer their specific question, however this should point people in the right direction for fixing the issue.

Community
  • 1
  • 1
Shalmezad
  • 475
  • 1
  • 4
  • 21
  • Well, I have 2 queues in my code, one concurrent and one serial. They are both managed by my app delegate and I'm positive I'm not creating any others. However, I am using ShinobiCharts and they are doing some background processing. It might be their code but I can't tell. I have already notified them but no word from them yet. – nemesys Jun 04 '15 at 15:35