Music App Stuff #5: Watchdogs and Waiting
The shape of logs to come…
We begin issue number five of Music App Stuff in medias res, too deep in the thick of things to give more than a passing mention to the newsletter name change. It’s 6:22AM and I’m working through the morning’s crosswords with a cat on my lap. Maybe it’s a little too early for Word of Mouf by Ludacris, but Word of Mouf by Ludacris is playing until all of the sudden it isn’t. God damn it.
I reopen Albums on my iPad, press play, and go back to the crossword. A minute or so later, it crashes again. Just for fun, I do the dance one more time, and yup, another crash. My very favorite crash — the crash I can’t ship 4.2 without fixing — is back. More accurately, I guess, it never went away. This crash and I have ourselves somewhat of a ritual.
After about two or three days of successful syncing across iCloud, one device or another will suddenly find itself in a crash loop. Anyone who develops for Apple platforms is no doubt familiar with the cpu_resource_fatal family of crashes. Basically, if you’re making the processor crunch through one task for too long without a break, your app gets killed. Albums is full of long-running jobs — the initial library import, the production credits download, and so on. I have each task pause every so often so that they don’t upset the watchdog and everything’s cool.
Not a single line of code I wrote is implicated in the crash report for this crash. It’s the built-in stuff responsible for keeping iCloud and local data in sync. But I can’t find anyone else on the entire internet who has had this problem — or anything that looks like it — so it has to be something I’m doing, somewhere, somehow. And with that, the Troubleshooting stage of the ritual begins anew.
I am pretty darn good at troubleshooting, if I do say so myself. I worked in IT for over ten years before I had the harebrained idea to tie having a roof over my head to the idea that a small minority of people want a tool to listen to music the same way I do, so I ain’t scared of a big-ass log. In fact, I find reading logs kind of meditative. There’s the actual information in a log, and there’s also the shape of it. A good log tells a story as you scroll through it. A bunch of short lines followed by a chunk of long ones, all the same length? Interesting!
So every three days or so I cozy up with a cat and a 50,000 line log. Scrolling through looking for pattens, then reading from beginning to end, I discover and fix a new chunk of raucously wasteful code I wrote when I was worse at this. Here are just some of the adorably terrible types of things I’m talking about:
A job that ran on every launch which calculated the total play counts of albums for every Artist, Playlist, Record Label, Producer, etc in your library, most of which couldn’t possibly have changed since the last time it ran, resulting in tens of thousands of modified records being sent to the server for absolutely no reason
A daily job that scanned every album in your library for changes and rewrote tons of metadata values even if they hadn’t changed, resulting in — you guessed it — thousands of modified records being sent to the server for absolutely no reason.
Faulty production credit deduplication code where you might end up with 6 copies of the same Producer, with different albums assigned to each copy. Once that synced across the cloud to another device it would add to duplicate copies on that device and really get the party started, syncing back and forth and multiplying.
These types of things didn’t matter much before, but they do now. Or at least I think they do. The logs look slightly different with each iteration of the ritual, and this most recent time was the longest it’s gone before the crash loop, so I have to believe I’m getting somewhere. In the days between crashes, I’m making great progress on the other features in 4.2 and let me just tell you, this update is a doozy. The app that exists here in the real world is starting to look more like the one in my head. I can’t wait to tell you more about it, but for now, I’ve made some new changes and it is time again for the final stage of the ritual: Waiting.
See you in two weeks.