Thursday, December 1, 2022

Long App Hangs Due to Spotlight

Whenever I mount a hard drive with lots of files, typically a clone drive, various other apps that deal with files often hang. An individual hang can last for minutes to over half an hour. If the app is doing a long series of file operations, which would normally take fractions of a second, it can be unusable until some time after the drive has been unmounted. This happens even though the apps in question are not accessing files on the hard drive. The problem has been occurring since Monterey but has gotten a lot worse in Ventura. It got to the point where I didn’t want to do any backups during the day since my Mac could essentially become unusable for hours, even after pausing or aborting the backup.

Sampling the hung apps shows that they are waiting (for an XPC process) to read or write Spotlight metadata. I don’t know exactly what’s going on, but it’s as if the newly mounted drive generates lots of potential work for Spotlight to update its index. You would think that each volume would have its own work queue, but it seems like there’s a single queue so that operations for the slow hard drive, which are not time-sensitive, block high-priority operations for the internal SSD. Maybe this is exacerbated by the fact that my clone drives get ejected after the backup completes so that the Spotlight index is always way out of date.

Once I traced the problem to Spotlight, the obvious workaround was to exclude those volumes from indexing. This is, in fact, effective, though it has some problems:

Some drives were stubborn, and I had better luck excluding them from Spotlight using a Mac running macOS 10.14. I hope to eventually get all of my backup drives excluded, at which point I expect the hangs to stop completely.

Previously:

Update (2022-12-02): Nicolai Henriksen:

Aha! Thats why! I have a TimeMachine backup disk that makes my entire machine halt completely whenever it is attached. It does not return to normal even when connected overnight. The TM disk was only connected once a week - until I gave up.

10 Comments RSS · Twitter


Matt Deatherage

There are so many moving parts to live indexing that it's hard to guess what might be going on. The output of the command-line tool "mddiagnose" confirms that, at least in Ventura, Spotlight is supposed to recognize any file named ".metadata_never_index" on external volumes for at least two directories deep, and ".metadata_never_index_unless_rootfs" files for external volumes with bootable macOS that are not your current startup volume. I'd think that adding those at the top level of your backup drives would prevent the problem.

mdddiagnose dumps a ton of information, and is best if you can execute it while it's hung (maybe a remote session?). My first thought, which is worth exactly what you're paying for it, is that there's an old .mdimporter plug-in somewhere, on its own or in an app bundle, that is behaving in ways the system did not expect.


@Matt Thanks. I had forgotten about mddiagnose but should give that a try. Based on what I was able to glean from samples, the bulk of the work is in tokenization and index compaction, not the importers. That’s what led me to think it was more about a large number of work items and unnecessary blocking.


As the author of Find Any File, I get quite a few mails from users who tell me that they completely disabled Spotlight for similar reasons. Since I'm still working mostly on High Sierra (on a far Hackintosh with lots of internal drives for backups), where I don't experience any such problems, I had trouble believing them. And when I use newer macOS versions, it's mostly on my laptops (on the road) or just for testing my software. Those don't get backed up much, or I leave them on for hours, where they can probably get all backups done and indexed. Though, even there I sometimes noticed many inexplicable second-long delays at the file system level. Yet another reason why I don't want to upgrade my main work system to the latest one, although many sites already don't work any more with the outdated Safari, but at least Chrome still gets updated on HS :)


Made the mistake of moving my user folder to a Samsung 980 Pro in a fast ACASIS enclosure. Beach balls are too frequent to bear in Ventura; sometimes it feels that any interaction that may write to UserDefaults can lock up the Mac for five seconds. Same deal on a fresh install, with no third party apps. In file transfers and benchmarking apps, however, the drive is as fast as advertised.


This is a great point!! I'm often seeing these weird pauses and also experience random Spotlight weirdnesses.
It gave me the opportunity to run mdimport -L to list all used mdimporters and clean up old apps that I don't *really* need to have on my Mac anymore and that hadn't been updated in years. I have hopes that one of the old mdimporters could be at the root of the slowdowns.
If anything it can't hurt to remove these old apps I had not used in years and that provide an mpdimporter…


This problem appeared for me after a late Mojave update. Now both my Mojave machines will become unresponsive for seconds, and even minutes, several times during a Time Machine backup, both over the local network or to an attached drive. I found that excluding the Applications folder helps somewhat but not completely.

What's weird is that for long periods (5-10+ mins) during the backup, nothing much seems to be happening. This coincides with the Mac becoming unresponsive. Looking at the Time Machine logs using Ulbow shows many, many entries with the following:

> com.apple.launchservices 9795323 186 Non-fatal error enumerating at , continuing: Error Domain=NSCocoaErrorDomain Code=260 "The file “PlugIns” couldn’t be opened because there is no such file."

I have no idea what this "PlugIns" file is supposed to me. If I allow Time Machine to backup the Applications folder, there will be hundreds of entries with this error about the mysterious "Plugins" folder

This error occurs on every Mojave machine I have, even one with a fresh install and during the first Time Machine backup.


Assuming this backup hard drive is a spinning disk and not a solid state or flash drive, I'm curious if the results would be any different if it was formatted as MacOS Extended instead of APFS.


@Josh Not 100% sure, but I think I also saw this with my drives that are still HFS+. APFS definitely makes things slower in general, though macOS is reducing support for encrypted HFS+ drives, and I do like having snapshots for my backups.


[…] activity display shows waiting for XPC processes, like the well-known Mac developer Michael Tsai analyzed in more detail in a blog entry from last week. He had already noticed the problem under Monterey, it was under Venturawhich officially started in […]


Very much explains the symptoms I've been experience for a few years!

Leave a Comment