Hi all! I'm at my first post, but think I have some useful information to share.
As correctly pointed out in post #79, in my case the slow shutdown was due to the
appleeventsd process hanging.
To discover it, I went through 2 steps:
- booting in verbose mode and checking the messages issued during shutdown; you may notice repeated attempts to quit a specific process; in my case, they addressesed some stuck com.apple.coreservices.appleevents task;
- launching the Console application from the Spotlight and browsing through one of the system-wide launchd-shutdown logs; in my case, I found that the above mentioned task was killed after an expired timeout of 20 seconds; not much surprisingly, my shutdown took 22 seconds (=20 seconds for the timeout + the usual 2 seconds I normally experienced for the shutdown).
So, the culprit apparently was a service managed by
launchd.
launchd is a daemon that takes care of starting, stopping, and monitoring many system-wide and user-specific services. From the documentation (man page) of
launchd.plist, when one of these services is to be stopped, it is sent a SIGTERM signal to halt gracefully. If it does not react within the predefined 20 seconds timeout, it is hardly terminated with a SIGKILL.
So, I have put the following
workaround in place.
The default timeout value can be changed by editing the .plist XML file that describes the service parameters. For the case of
appleeventsd, this file is
/System/Library/LaunchDaemons/com.apple.coreservices.appleevents.plist. So, I made a backup copy of this file and carefully edited it by adding the following 2 lines right before the two final closing tags </dict> and </plist>:
<key>ExitTimeOut</key>
<integer>2</integer>
Be
very careful when editing this file and, really,
make a backup copy, because there are chances that a wrong edit may screw some system components (most notably, the Finder application).
It took a reboot cycle to make launchd fetch the updated timeout value, but this did the trick: the appleeventsd service is still reported as stuck during shutdown, but at least only 2 seconds are waited before giving up waiting, totaling 4 (=2+2) seconds of shutdown time. I know, it's a very dirty workaround but, until a proper fix comes, it makes me very happy!
A couple of side notes:
- In my personal experience there have been different services intermittently affected by this issue but, ultimately, killing appleeventsd seems to have (hopefully) permanently solved the slow shutdown problem for me.
- I have just noticed that a similar solution has already been independently posted elsewhere: https://discussions.apple.com/thread/4339540?start=60&tstart=0. If only I could find it earlier...
I would really like to also post this to the relevant Apple Discussions forums, but it seems the system decided not to let me even create a nickname, leaving me with a mysterious "An unknown error has occurred" message. Apparently, logging in to Apple Discussions is another problem that has been suffered for long by many people, therefore I'm giving up on that (for now...)
I hope this helps someone.