X

Managing unexpected quits and hangs after waking from sleep

Putting your Mac in Sleep mode is a good way to restore the system to its last state so you can continue your work where you left off; however, it does not come without a few potential drawbacks.

Topher Kessler MacFixIt Editor
Topher, an avid Mac user for the past 15 years, has been a contributing author to MacFixIt since the spring of 2008. One of his passions is troubleshooting Mac problems and making the best use of Macs and Apple hardware at home and in the workplace.
Topher Kessler
5 min read

Putting your Mac in Sleep mode is a good way to restore the system to its last state so you can continue your work where you left off; however, it does not come without a few potential drawbacks. One of them is that even though OS X is designed to be run continually without needing to restart, sometimes going for a period without refreshing the system with a restart can result in a few periodic pauses and slowdowns.

Not only can small slowdowns occur, but when the system wakes from sleep all the processes are brought back into memory at once in an active, running state where they may be queued up for performing various tasks. Usually these processes receive messages and perform these tasks at a regular pace, but when the computer is awakened they all might be looking to complete overdue tasks at the same time. As a result, you may see a flurry of activity when you wake your system (synchronizing, backing up, checking e-mail, and establishing Internet connections), and as a result things might crawl for a few seconds.

It is never a good thing to see unexpected quit warnings after waking from sleep.

While all of these routines should be able to run simultaneously and complete their tasks, there are times when all this activity can choke some processes and potentially cause them to crash, and when this happens to one on which others are either directly or indirectly depend, then you may see a series of pauses and hangs in your system.

Recently upon waking my desktop from sleep, such an event occurred. The computer was fine for a few seconds, but then the foremost application (Safari) started to hang, showing the spinning color wheel. From here, the number of hung processes seemed to increase as I tried to access them. Opening a file on the desktop caused the Finder to hang, and then accessing the Dock resulted in it hanging as well. Despite this, the system's window server was still functioning because window elements could be moved around on the screen.

The progressive increase in hung processes (as opposed to the whole system freezing at once) suggested one possibility being an underlying dependent routine was not responding and causing the applications I interacted wtih to pause. It is good to keep in mind that another possibility for these kind of pauses and hangs can be filesystem errors or other hardware malfunctions; however, hardware issues usually manifest more frequently and so far this appeared to be a one-time problem.

It appears a problem with the Cocoa framework caused the crash, but this could be from improper access of cached system files or overload from other running routines.

Hard rebooting is always a consideration during hangs, but since this can lead to further problems I decided to wait it out. It is best to give the system as much time as possible to clear the problem, rather than hard-reboot it when the software may be in a vulnerable state.

After waiting a few minutes, the problem resolved itself and a problem report appearted mentioning the application "PreferenceSyncClient" had unexpectedly quit, referencing a problem with the Cocoa frameworks. This was likely just a temporary issue from the Cocoa resources not being available when the system was woken from sleep, but there were some side-effects such as the clipboard not working and the Finder not being able to rename files (highlighting them and pressing enter just made an alert chime). These issues cleared up after a few minutes, but I decided to restart the system to be on the safe side and ensure everything was loaded properly. The system has been running fine ever since, though I did perform a surface scan of the hard drive and checked the diretory structure with Drive Genius to ensure the filesystem was healthy.

There can be many reasons why a these kind of hangs and pauses can happen. One is if you have too many applications loaded and running at once (all of which reactivate at the same time when woken from sleep), and another is if your system is low on hardware resources such as RAM or hard drive space, resulting in excess virtual memory swapping when the system is woken up.

There is also the possibility that these problems may happen from recent cleaning routines. Cleared caches and other temporary items from a cleaning routine will require a rebuild, and if system services are not properly cached after the cleaning then it is possible errors may occur when these caches are accessed, such as after the system wakes from sleep.

I had recently run a cleaning routine on my system and only performed one reboot after its completion, which may not have been enough to rebuild the system caches and could have been a contributing factor to the hang and crash after sleeping.

Be sure after running cleaning routines that you reboot several times. The first reboot is expected to be a little slower than usual, so restart the system again and run a few common applications (just launch and quit them), and then restart the system one more time. Then run the system normally and allow various background services such as Time Machine and MobileMe syncrhonization to complete. After this you can restart the computer again as an option to ensure the system is booting and running at normal speed, but this is not necessary.

Overall, the best solution when these kind of pauses and hangs happen is to wait it out. Give the system a decent amount of time (up to 30 minutes, if you can spare it) to clear these hangs itself and in the meantime do not just click everywhere. The best practice is to perform one small user input task such as opening a folder that will not open, clicking a window that will not come into focus or clicking an application to launch it, and then sit back and wait. This will queue the input command so when the hang clears itself the command will be run and the window will come into focus.

Note that while this problem stemmed from an error with the MobileMe synchronization routines, it does not necessarily indicate a problem with these routines. As mentioned it is likely improper caching or other slow access during wakeup caused the issue; however, if the same service continually unexpectedly quits then you could be having a problem with your sync services or a third-party notification service such as Growl that interacts with the sync services, and resetting or uninstalling them may help. Alternatively, you can turn off the "Preferences" option in MobileMe's system preferences pane to keep a continual error messages from popping up.



Questions? Comments? Have a fix? Post them below or e-mail us!
Be sure to check us out on Twitter and the CNET Mac forums.