Apple Intelligence is now available on iPhone, iPad, and Mac!

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Music hangs on Saving Music Library

This question has been posted before many times and never successfully answered. This is specific to Music.app with local files. Apple Music is turned off.


For context, my old iMac running Catalina with Music 1.0.6.10 has no problem with my music library which has about 275,000 tracks in it. (I work in radio so I have a lot of music).


This problem crops up when I try and restore/convert the Music to a new machine running Ventura.


Music seemingly hangs on quitting, showing "Saving music library..." for a very long time or forever. I've lost track after 24 hours and then force quit it. However, I find that when it's force quit, when it opens again, it has lost the location of my files.


If I get info on a song, I can see the path where it thinks the file is. But if I look on the disk, that file doesn't exist, BUT there is a file with the same name with the track number preceding it. So "Keep Organized" has updated the file name to include the track number, but the iTunes database didn't get saved after updating.


Songs that didn't have a track number in their info field are still found.


I've repeated this many times by restoring backups and trying again.


When I let the "Saving music library..." box do it's thing after 10 hours, I go and look at modification times for the files inside ~/Music/Music/Music\ Library.musiclibrary nothing has been updated.


This leads me to think it's a bug in the code that's causing this hang, and that it's related to "Keep Library Organized" and for some reason, the Music database isn't getting updated.

Posted on Jan 17, 2023 5:09 PM

Reply

Similar questions

20 replies

Jan 18, 2023 1:59 PM in response to Rusty SomaFM

To be clear this is happening when Music on Ventura attempts to update a Music library originally created in Catalina? Or for any operation in Music on your new machine? I've been tracking an issue with Music in Monterey not converting .itl files, but I haven't heard of anything similar with Ventura. I'm not familiar with lsof, but the general process when iTunes or Music update their files is that they write out a new copy as a temporary file, then delete the original and rename the temp file to replace it.


Probably won't be relevant, but just in case see Repair security permissions for iTunes/Mac for Mac - Apple Community. You can also try holding down option+cmd as you launch Music to open it in safe mode, which can sometimes fix odd issues. Another thing is to option-start-Music and explicitly reselect the library you want it to open in case it is working with a cached copy somewhere which it cannot update.


tt2

Jan 18, 2023 1:41 PM in response to turingtest2

This is a fresh, new machine with minimal software installed and definitely no third-party security software. No .tmp files. There is a 'sentinel' file that gets created when Music.app is launched.


I've tried running "sudo fs_usage -f pathname Music" from cmd line to see what files it's opening/reading/closing, as well as doing. I've run find to dump all files in the library to a textfile, and then 30 minutes later do it again to see if anything changed. Which it hasn't. (I also used this procedure to confirm that when experimenting with checking and unchecking Keep Files Organized that I can see what it was doing... and that's how I know it was actually renaming all the files to have the track number in front of them.


But something is keeping the library database from being written to.


I have even tried creating a new account, and making a fresh copy of the music library, and loading it in, and it still hangs on exit, infinitely showing "Saving Music Library". OK maybe not infinite, I'll let it go for a much longer while and let you know. But it's already been going 30 minutes.


Edit: While it's saving, I'm running 'sudo lsof | grep XXX' where XXX is the PID of the Music app. I'm looking for changes, and nothing is changing. And looking at the mod times for all those open files from the Music app, none of the mod times have changed since I initially selected quit on the Music.app. (It's been an hour...) Even the timestamp on the sentinel file is old, but not as old as the timestamp on Library.musicdb


Jan 18, 2023 2:44 PM in response to turingtest2

Correct. this is happening when Music on Ventura attempts to update a Music library originally created in Catalina


lsof is a command line tool to show all open files, by process ID. It's useful for debugging and to see what files a program is changing/updating. (It's basically the same thing as showing open files from Activity Monitor when you get more info on a process).


I tried the option-start-Music as well, same results.


If I open the library, and don't do anything, if will close and NOT hang.

But if you play a file (which seems to rename it to the '01 Title' format from just 'Title' based on changes to the file system I see), it will hang on closing again.


I also confirmed that everything has read/write access.


So when I open it in safe mode, and click on a file, it will sometime play. Othertimes, another song than I click plays, and if I click the original again, it will play. BUT when I look at the file system to see what has changed, I see the file I clicked that didn't play at first and then played the 2nd time has been renamed to the "01 Name" format. And on top of that, in safe mode, it closes quickly. (Safe Mode still takes about 5 or so minutes to load the library).


What all does safe mode do that might change this behavior? I shouldn't have any plugins (it's a fresh install).


My ned step is doing the "Uncheck Keep Files Organized" routing and then re-checking it, which will make it re-org the whole library IN SAFE MODE to see if that fixes things. It takes about 90 minutes to do this, so I'll update later today.

Jan 18, 2023 2:54 PM in response to Rusty SomaFM

One more thing to add. This library goes back a long way. When iTunes 8 came out and removed the option of not including the track number in the file name, there was a way do disable it this way:


defaults write com.apple.iTunes create-filenames-with-tracknumber -bool FALSE


That seems to be carried over into Catalina/Music with 'addTrackNumber'


defaults read com.apple.music   addTrackNumber
0


Apparently now, versions post Catalina no longer respected this setting.

Jan 18, 2023 6:11 PM in response to turingtest2

In Safe Mode, it took over an hour for Music to "keep files organized", but now when I got to quit, it hangs again.


I did confirm by scanning the file system that it did rename everything at the file system level. Historically, if I force quit now, and restart, the library will be pointing to the old, pre-renamed files.


So unfortunately, that hasn't fixed it. The .musicdb isn't getting updated.


I'll let it continue to run overnight on the off chance something changes.


I've been saving "Samples" of the process from Activity Monitor, and will submit those with a big report to Apple.


@turingtest2 do you know of any tools to let you dump (or ever write to) the .misicdb database?

Jan 19, 2023 3:37 AM in response to Rusty SomaFM

Rusty SomaFM wrote:

@turingtest2 do you know of any tools to let you dump (or ever write to) the .misicdb database?


No. I've written scripts that interact with Music, but nothing that accesses the database directly.


At this stage I'd be tempted to reinstall Ventura over the existing installation to repair any issue with Music. Something is not working as it should on your system. The only other approach might be to try opening the Catalina library in say Monterey, then seeing if the version made by Monterey will open in Ventura and save correctly. FWIW I have access to both. I've been converting .itl files for Monterey users remotely. I could see what happens with your library if you like. I'd need the .musiclibrary package zipped up and sent in an email, or a link to it in a cloud share. I could then see if it will convert to a working Ventura library at my end and post it back. Check the bio in my profile here if you'd like me to try.


tt2


tt2

Jan 19, 2023 11:39 AM in response to turingtest2

Thanks for the offer, but I have actually done all you suggest before. Problem first discovered when moving to Monterey (and tested on brand new machine / clean install).


One thing I didn't try yet is converting on a Big Sur machine. The other thing I'll try is moving it to a new virgin Catalina install on another machine, and confirming has the normal 'addTrackNumber' preference setting and doing the force music library organization there.


(By the way, for those following along at home, after 24 hours the Ventura machine was still stuck on the "Saving Music Library" alert)


I'll keep everyone posted to what I discover.


Jan 19, 2023 2:46 PM in response to Rusty SomaFM

I thought I found the culprit: I was able to open the library and before saving, turned off "Keep Music Folder Organized". At that point, it seems to be able to quit properly. However the next time I launched it, the Keep Files Organized got turned on again somehow, and as I played songs, it renamed them. And after doing that with about 25 songs, when I now quit, it hangs again.


So I loaded a fresh clone of the original library again, opened it, turned off "Keep Music Folder Organized" again, played some files to let them update the last played times in the database, then quit. AND IT HANGS again.


So something is causing a hang when the database changes and it seems tied to the Music Library database being on an external drive.




Jan 19, 2023 5:49 PM in response to turingtest2

The external drive is APFS SSD. But I've also had the same issue when copying the library to the internal drive on the Ventura machine as well... but I just did a test which I copied the library into a new location on the internal SSD and opened that via the Command-Open option to select the library. Made sure Keep Library Organized was unchecked, played a few songs to get their last played time set, and it seemed to work. Quitting was fast, opening was slow like normal but after that worked ok.


So now I'm setting back on the Keep Music Folder organized, it took over an hour to do that. I took a look at the file system to confirm the files have been renamed with the leading track number. And they play properly, etc. So now comes the final test: quitting. And so far, after 25 minutes, it's still saving.

Jan 20, 2023 7:38 PM in response to Rusty SomaFM

I was having the same problem after having moved my library on my NAS. I ended up restoring my library from Time Machine back to my laptop but was still having the same problem so turned off Keep Music Media folder organised and left Copy files to Music Media folder when adding to library on. After restarting Music, everything is now working smoothly again. I think it was the automatic file renaming and organising that was causing the problem and it really made a mess of the files on the NAS with albums being split across folders, moved to Collections or even disappearing completely. I will try to copy a clean library back to the NAS but will manually do any file renaming or organisation in future.

Jan 22, 2023 2:15 PM in response to myalterego

This part "the automatic file renaming and organising" seems to be the key.

I spent many hours yesterday working on this, and still haven't found a reliable solution; but I think the root cause of the problems were due to having 2 similar files that only had a difference I the case of their names, on a normal, case-insensitive file system. Keep Folder Organized would overwrite files in an album name folder if the case was the only thing different.


And because the filenames are Unicode, that makes doing checks for case a bit harder.


Your NAS probably uses a case-sensitive file system. APFS and HFS+ default to non-case-sensitive.


But this definitely seems like a big in Music.app that's causing this hang.

Jan 23, 2023 7:18 PM in response to Rusty SomaFM

I thought I solved this, and it seemed to work, until I quit it and restarted; then the files got lost again.


Here's what I did that I thought finally fixed things:


1. Made a clone of the original media library on a blank APFS case-insensitive hard drive. (Same as the original on Catalina).


2. Copies the (Catalina) Music Library database (with a new name) to that filesystem as well.


3. Plug that disk into a Monterey machine, opened with Command to choose a new library, and selected the library. This takes a couple minutes to load.


3a. Make sure "Keep Library Organized" is turned off.


4. Music -> Preferences -> Files and change the Media Folder Location to a new folder on a second, empty 4TB SSD. DO NOT CHECK "Keep Media Folder Organized"


5. Spot check your library by playing a few tracks. I did Cmd-I Get Info, under the File tab check the location to confirm that they were on the disk I started with.


6. File -> Library -> Organize Library. Check Consolidate Files. Press OK, cross your fingers and wait a very long time. (At least it will give you a dialog listing all the files it is copying to the new disk). This took about 12 hours for 3TB and 275k tracks.


7. Come back many hours later. Spot check some files via Command-I Get Info -> File Tab and confirm the location in the new disk.


8. Quit Music.app and cross your fingers.


But I'm not sure why when I re-opened things the 2nd or 3rd time that the library database lost track of files again. It's like something was getting cached somewhere, and the cache was outdated.


Today, I have tracked down another Catalina machine to experiment with. I'll report back hopefully tomorrow what I learn. ¯\_(ツ)_/¯



Music hangs on Saving Music Library

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.