mikeash.com: just this guy, you know?

Posted at 2012-05-07 20:06 | RSS feed (Full text feed) | Blog Index
Next article: Friday Q&A 2012-05-18: A Tour of PLWeakCompatibility: Part I
Previous article: Friday Q&A 2012-05-04: PLCrashReporter and Unwinding the Stack With DWARF, Part 2
Tags: apple hack xcode
Solving Simulator Bootstrap Errors
by Mike Ash  

I'm sure every iOS developer has seen the dreaded bootstrap error. "Couldn't register com.yourcompany.yourapp with the bootstrap server. Error: unknown error code. This generally means that another instance of this process was already running or is hung in the debugger." After nearly throwing my Mac out the window for the Nth time today, I finally managed to come up with a simple fix. Run this in the shell: launchctl list|grep UIKitApplication|awk '{print $3}'|xargs launchctl remove. And your bootstrap errors magically melt away.

This occasionally happens when using Xcode to run iOS apps in the simulator. Although the error really gives no indication of it, it's apparently a hung launchd job that somehow doesn't get cleaned up. The above command lists out all launchd jobs, searches for one with UIKitApplication in the name (which will be the job corresponding to your app that's improperly sticking around), extracts the name, and tells launchd to get rid of that job.

I'm still not sure exactly why this error happens. And, as far as I know, the above can't be used on the actual device, so you still have to reboot those to solve it when it happens there, although that's much less painful than rebooting your development Mac. But the above works just fine as a workaround until Apple can get their act together on this problem. I saved the command into a shell script called unfuckbootstrap that I can use whenever Xcode decides to screw up.

Did you enjoy this article? I'm selling whole books full of them! Volumes II and III are now out! They're available as ePub, PDF, print, and on iBooks and Kindle. Click here for more information.

Comments:

Thank you so much! I like the script name.
Mike,

I had this problem... maybe... a dozen times. Since nothing comes up when you hit 'ps'... i always ended up restarting whe mac. (Or switching from device to simulator... when it gets screwed up, you can still use one or another).

THANKS!!!
Many thanks for the pointer, you might have just saved another Mac going airbourne
Mike,

I am not sure what kind of sick irony caused this, but this script seems to have actually caused the problem to appear. Altho I have not had the bootstrap error for a few weeks, it used to plague me incessantly. Rebooting three or four times a day really stinks. So, I created a unfubarbootstrap.sh with your commands in it and test ran it, figuring this should be a no-op. Now, Xcode is throwing the bootstrap error.

I am not blaming you Mike, and thanks for tracking down the problem so specifically. Hopefully I won't ever need the script again :)
Mike,

I am glad someone finally came up with a solution..that i cannot try : your solution seems to be the one because of the keyword "UIKitApplication", but what if all these commands should be ran on the device itself ?
I am facing this right now : device is unplugged from Xcode, and when i launch the app, it crashes with that log:

unknown com.apple.launchd[1] <Warning>: (UIKitApplication:com.************[0x4fd9]) Conflict with job: UIKitApplication:com.************[0x74e7] over Mach service: com.************
unknown com.apple.launchd[1] <Warning>: (UIKitApplication:com.************[0x4fd9]) Conflict with job: UIKitApplication:com.************[0x74e7] over Mach service: com.************.UIKit.migserver
unknown com.apple.launchd[1] <Warning>: (UIKitApplication:com.************[0x74e7]) The following job tried to hijack the service "com.************" from this job: UIKitApplication:com.************[0x4fd9]
unknown UIKitApplication:com.************[0x4fd9][467] <Notice>: Couldn't register com.************ with the bootstrap server. Error: unknown error code.
unknown UIKitApplication:com.************[0x4fd9][467] <Notice>: This generally means that another instance of this process was already running or is hung in the debugger.

Any idea ?
The only solution I know of for the device is to reboot it. Fortunately, this is much less painful than rebooting your computer, but still pretty annoying.
Mike,

Thank you so much for this. I've been bitten by this error many times, but I've always been so busy with the actual project, that I really didn't have the time to investigate and find a solution.

Thank you for doing it for all of us.
Also, on a side note, love the shell script name.
One easy way to resolve the problem is to launch activity monitor and see in process list, you will find a process related to simulator just quit the process, and try to run and build , the problem is resolved!!!
super like, i always stuck with this error
I have been messing with launchctl trying to resolve this...then I came across your fix and thought "Great!"...except...it's still not working for me...

Here is the output of launchctl list | grep UIKitApplication
36335    -    UIKitApplication:com.company.iphoneTest[0xef85]
36276    -    UIKitApplication:com.company.iphoneTest[0x8256]


When I try to run the script, I see the following:

usage: launchctl remove <job label>

I have even tried just executing it on portions of that label, ie without the bracket + address..

I'm stumped :-/ any ideas?
A friend ran into that as well and I'm not quite sure what's going on. You can get the script to kill the two jobs individually by adding '-L 1' to the xargs command. However, it still didn't work for him even with that. Restarting Xcode (not his computer), however, did.
Interesting...I had killed the simulator and Xcode prior to trying... Ironically, I was able to get this "bootstrap" error to happen on purpose, in order to test out your fix...and now I can't fix it, haha.

Sadly, this did not help me at all - I got the double list like Eric, "launchctl remove" did not work on either entry. Restarting XCode did not help, or the simulator. I was forced to reboot as always.
No such luck for me. I get:

    launchctl remove error: No such process


And I guess I just have to restart.
Long running issue on SO:

http://stackoverflow.com/questions/788277/iphone-strange-error-when-testing-on-simulator/7860828#7860828

I've tried a lot of approaches. I'll have to give this one a shot. I may have missed this as a separate launchd job (though it sounds like people have had mixed results ...)


Yeah, didn't work for me either. Damn
I believe the simulator will clear all UIKitApplication launchd jobs when you launch it, so you should be able to just quit and relaunch the simulator? Or does that not do the trick?
I tried restarting everything in sight, and nothing short of restarting the computer would do it for me.
I had a similar error when switching between iOS 5 and 6 simulators. The simulator app would just become unresponsive.

This article led me to the problem: launchd was still restarting springboard and other iOS jobs from the older simulator when I wanted to start the newer version.

Removing all simulator jobs did the trick. Here's my updated unfuck script:

jobs=`launchctl list | grep -E "iPhoneSimulator|UIKitApplication" | awk '{print $3}'`

for job in $jobs
do
    echo "launchctl remove $job"
    launchctl remove "$job"
done

Comments RSS feed for this page

Add your thoughts, post a comment:

Spam and off-topic posts will be deleted without notice. Culprits may be publicly humiliated at my sole discretion.

Name:
The Answer to the Ultimate Question of Life, the Universe, and Everything?
Comment:
Formatting: <i> <b> <blockquote> <code>.
NOTE: Due to an increase in spam, URLs are forbidden! Please provide search terms or fragment your URLs so they don't look like URLs.
Hosted at DigitalOcean.