[launchd-dev] Bug in Lion: WatchPath agents succeed, but respawned for a second launch

Jerry Krinock jerry at ieee.org
Thu Jul 28 09:48:34 PDT 2011


In Lion, launchd tasks with a WatchPath trigger are triggered as expected, but are then respawned to run after a second time after their ThrottleInterval.  This does not happen in Snow Leopard.

One would think that this bug might have something to do with document Auto Save if the WatchPath was opened in an app that had Auto Save enabled, but that is not necessary; as shown in the steps below, it occurs if I simply 'touch' the WatchPath.  Same thing happens if I modify the WatchPath file in BBEdit 9.0, which does not have Auto Save enabled.  Also, this bug does not require opening a text file; I discovered it by testing my app which launches a background tool which works for about 10 seconds and then quits.  When running under OS X Lion, it always gets launched twice.

Please look at my steps below and tell me if my expectations are incorrect.  Does anyone think that this is not a serious bug in Lion?

Thanks,

Jerry Krinock


STEPS TO REPRODUCE:

1.  Create a target text file named "Junk.txt", with any text, in your Home folder.
2.  Create a trigger text file named "TriggerFile.txt", with any text, on your Desktop.
3.  Create a launch agent file named "jerry.launchd.test.plist" in ~/Library/LaunchAgents containing the following text:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>jerry.launchd.test</string>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/bin/open</string>
        <string>/Users/jk/Junk.txt</string>
    </array>
    <key>ThrottleInterval</key>
    <integer>61</integer>
    <key>WatchPaths</key>
    <array>
        <string>/Users/jk/Desktop/TriggerFile.txt</string>
    </array>
</dict>
</plist>

where, of course, you have replaced /jk/ with /yourShortName/.

4.  Load the agent file by running this command
        launchctl load ~/Library/LaunchAgents/jerry.launchd.test.plist.

5.  In Console.app, open a window to System Log Queries ▸ All Messages.

6.  Trigger the agent by running this command:
        touch ~/Desktop/TriggerFile.txt

Expected and Actual Result: The file Junk.txt opens in your text editor.

Additional Unexpected Results: 
    Message is logged into Console:
        com.apple.launchd.peruser.501: (jerry.launchd.test) Throttling respawn: Will start in 61 seconds

Note that 61 seconds is the ThrottleInterval.

7.  Close the window to Junk.txt which has opened.

Additional Bad (but not unexpected) Result: 
    The window to Junk.txt opens *again* 61 seconds after the first opening.

Regression: Repeat the test in Snow Leopard; the target file is only opened once, as expected.



More information about the launchd-dev mailing list