-[NSWorkspace launchApplicationAtURL:options:config...] fails sometimes

Originator:kelan
Number:rdar://10952677 Date Originated:2012-02-29
Status:open Resolved:
Product:Mac OS X SDK Product Version:OS X 10.7.3
Classification:Serious Bug Reproducible:Sometimes
 
Summary:
The -[NSWorkspace launchApplicationAtURL:options:configuration:error:] method
sometimes fails, saying the app is corrupt, with error code -10827 (which
LSInfo.h says is "The executable is missing".  Using -[NSWorkspace
launchApplication:] always succeeds.


Steps to Reproduce:
1) Open the attached project.
2) Build the LaunchTarget target.
3) Build and run the Launcher target.
4) Press the "Launch w/ Env" button.


Expected Results:
The LaunchTarget app should launch, and be passed an environment variable of
test_key=test_value, which will cause the LaunchTarget app to show:
    Got envar:  test_key= test_value


Actual Results:
I often get the result (shown in the Launcher app's window):
    error: Error Domain=NSCocoaErrorDomain Code=3584 "The application
    “LaunchTarget.app” could not be launched because it is corrupt."
    UserInfo=0x102929ae0
    {NSURL=/Users/kelan/Library/Developer/Xcode/DerivedData/LaunchTest-eslrhyybedrznegdutegsiaqsnze/Build/Products/Debug/LaunchTarget.app,
    NSLocalizedDescription=The application “LaunchTarget.app” could not be
    launched because it is corrupt., NSUnderlyingError=0x102927ac0 "The
    operation couldn’t be completed. (OSStatus error -10827.)"}


Notes:
 * The "Launch w/ Env" version uses -fullPathForApplication: to determine
   the path to the app, and shows the path it gets in the window for
   verification.

 * The "Launch Simple" button (which uses -launchApplication:) always works.
   This version doesn't (and can't) pass any environment variables to
   LaunchTarget, so that app will launch showing "test_key= ()".

 * Sometimes, the "Launch w/ Env" does actually work, and the LaunchTarget
   app will correctly show "test_key= test_value".  And once it starts working,
   it will continue to do so, until the LaunchTarget app is re-built.

 * I'm not sure what the trigger is to make it start working.  I thought that
   maybe the app had to be launched once first "manually" before LaunchServices
   would correctly know about it.  But that didn't turn out to be the case (and
   -launchApplication: always works, even immediately after rebuilding
   LaunchTarget, and that one doesn't even take the full path to the app, so
   clearly LaunchServices has no trouble "knowing about" the LaunchTarget app
   when it is re-built).

 * Since this method isn't reliable, there is no way to launch an application
   using NSWorkspace and passing it custom options/arguments/environment
   variables.

 * Some web-research suggests others are running into a similar issue with
   Sandboxed applications, and that manually launching the app first will
   cause the method to work after that, but that isn't the same case here,
   becuase neither of these apps are Sandboxed, and that first manual launch
   doesn't solve this problem.

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!