inessential by Brent Simmons

February 2020

How We Fixed the Dreaded 0xdead10cc Crash

NetNewsWire for iOS, currently in TestFlight beta, was getting a lot of crashes related to background refreshing.

They would happen when the user wasn’t actually using NetNewsWire — it happened when the app would download feeds and sync in the background.

The crash logs were not identical, but they had this same thing:

Namespace RUNNINGBOARD, Code 0xdead10cc

This meant that the system was killing the app because, after the background task was complete, the app still had references to a SQLite database (or sometimes another file).

We did everything we could to fix this over a course of several months, including various forms of major surgery — and the best we could do was make it worse.

I did a lot of research — including reading this blog post from The Iconfactory several times — and we still came up with nothing.

Finally I asked around.

Advice

Marco Arment writes Overcast, a podcast player, which is in some important ways similar to NetNewsWire: it downloads data from the web while in the background.

Marco had already been through all this with Overcast, and he gave me this advice:

Don’t keep the SQLite database in the shared container. You’ll never get rid of all of those crashes. Instead, communicate with extensions via other means than having them read/write the DB directly, such as Darwin notifications or writing plist files in the shared container.

iOS will always terminate the app and generate that crashlog whenever your app or extension has an open file handle to a file in a shared container at suspension time.

And there are some cases where your app gets forcibly suspended without calling background-task completion handlers. (Especially in extensions, where they don’t exist.)

I tried wrapping every SQLite query in a background task once to avoid this. A standard Overcast session may issue hundreds or thousands of database queries. I later found that apparently each one generates a process power assertion, the OS wasn’t made for that level of usage, and after some time, Springboard would crash.

There’s also the NSProcessInfo background-task thing that allegedly works in extensions, except that it doesn’t.

The moral of the story ended up being: just don’t keep your SQLite database in the shared group container. There’s no way to avoid these crashes 100% of the time.

We were sharing our SQLite database with one of our extensions! Marco’s advice is, basically, don’t do that.

So we stopped doing that. We un-shared the databases and switched to a super-low-tech thing for communicating between the extension and the app (the extension writes to a plist file which the app later reads).

And — as of last night’s build — the dreaded 0xdead10cc crashes are gone!

Continuing On

That was the last big challenge on our list for shipping. We still have work to do, but we’re getting close — the milestone says we have just four bugs left. Good deal.

PS I’ve since heard from other developers: don’t-share-the-database appears to be the common wisdom, which it just took me longer to learn. 🐥

Knock It the Fuck Off

Every day on Twitter I see smart people who I respect dumping on one or another of the Democratic candidates.

Sanders for being cozy with left-wing dictators; Warren for being insufficiently socialist; Klobuchar for having prosecuted drug crimes; Buttigieg for taking money from rich people and for his lecturing; Biden for the stains on his record and for being weird; Steyer for being super-rich; Bloomberg for being even richer and for stop-and-frisk; Yang for… something, probably. (I forget).

I have a favorite, and a second and third choice. And so do you, and ours might not match.

Odds are that your favorite is not going to be the nominee. And that nominee, whoever it is, needs to not have been already labeled a garbage candidate by you and by everyone who’s favorite he or she isn’t.

Here’s the thing: we’re fighting to stop the spread of right-wing extremism. It will get so much worse if we reelect the president. It has to be stopped now. No other issue matters, because nothing else can be done without doing this.

Things I Don’t Care About

I don’t care about Medicare for All or beefing up the ACA. I don’t care about free college. I don‘t care about legalizing marijuana. I don’t care about immigration reform. I don’t care about rolling back the corporate tax cuts.

I don‘t care about any of the wonderful liberal and progressive policies our candidates propose — because they’re not going to get through.

(Well, I do care about them, deeply, but the point stands.)

It’s not that it would take 60 Democratic senators — it would take more like 65 or even more, and that’s not going to happen. We can elect the most wonderful progressive person ever and they’ll just beat their head against the wall.

There’s no magic coming. There’s no amount of will-of-the-people that will move Republican senators. All of the policy we talk about is just fantasy.

I also don’t care where the candidates’ money comes from. In fact, I want it to come from everywhere and I want to see enormous fucking rivers of it — because we’re going to need it to beat that corrupt asshole, our current president.

The Only Thing I Care About

Our job is to stop fascism here in America.

And then we can deal with it in the rest of the world.

I have plenty of doubt about what’s the best way. Will we turn out people who don’t usually vote? Maybe. But, the thing is, those people are people who don’t vote. And there’s no guarantee that, if they did, they’d vote our way.

But maybe there is an untapped well who can be energized and inspired?

Or… instead, will we be able to persuade people in the suburbs who normally vote Republican? In this polarized country, can anyone anywhere be persuaded? I don’t know. But maybe?

If you think you know the answer, I’ll tell you you’re full of shit, because you don’t know and I don’t know.

Here’s what I do know, though: we all need to be prepared for one of these candidates becoming the Democratic nominee, and we need to not have half of us hating that person already.

Because none of them are right-wing extremists. They’re all good people who will do their best to get good things done (and fail, but still).

This is the only thing that matters — they would all, every one of them, turn us away sharply and swiftly from the abyss we’re looking at right now. Even the ones who are not your favorite.

So cut it out.

NetNewsWire Sitrep

Alex — @tales on Twitter, blogger at 418 Teapot — ran Sitrep on NetNewsWire, on the branch we’re currently working on (iOS-candidate).

Here’s what Sitrep reports:

SITREP
------
Overview
   Files scanned: 424
   Structs: 145
   Classes: 283
   Enums: 33
   Protocols: 69
   Extensions: 300
Sizes
   Total lines of code: 56254
   Source lines of code: 50125
   Longest file: SceneCoordinator.swift (2038 source lines)
   Longest type: SceneCoordinator (1080 source lines)
Structure
   Imports: Foundation (218), RSCore (146), Account (129), Articles (104), UIKit (91), AppKit (79), RSWeb (53), RSParser (42), XCTest (41), os.log (37), RSTree (20), RSDatabase (18), ArticlesDatabase (13), SyncDatabase (12), WebKit (9), SafariServices (6), UserNotifications (5), CoreServices (4), Intents (3), NetNewsWire (2), MobileCoreServices (2), Social (1), CoreSpotlight (1), SystemConfiguration (1), WatchKit (1), BackgroundTasks (1), Sparkle (1), Darwin (1), AuthenticationServices (1)
   UIKit View Controllers: 7
   UIKit Views: 5
   SwiftUI Views: 0

I would have guessed around 35,000 lines of code, but we’re past 50,000 lines.