BlockEdge

Technology and digital life

An intermittent iOS crash traced to a main-thread requirement for HTML import

An urgent hotfix reduced the overall crash rate in a widely used iOS app, but the crash that prompted the fix kept appearing. The developer investigating the incident eventually traced it to the disclosure text on two screens. The app converted that text from HTML into an attributed string without guaranteeing that the conversion ran on the main thread.

What the first hotfix missed

The crash reports contained a SIGBUS signal and Foundation stack frames associated with rich-text processing, but they did not identify a failing line of Swift. The signal indicated an invalid memory access; it did not establish that an object had been released too early. Neither developers nor QA engineers could initially reproduce the failure reliably.

With about a week to investigate and prepare a fix, the developer checked object lifetimes, ownership and asynchronous calls. The first hotfix tightened ownership and synchronization and made UI isolation more explicit. Although the overall crash rate fell, users still reported problems and the same stack signature continued to appear. The developer noted that changing when tasks run or how long objects remain alive can make a timing-sensitive failure less frequent without removing its cause.

One device made competing explanations testable

A QA engineer found that repeating the affected workflow on her device could trigger the production crash, sometimes after four or five attempts. A successful run still proved little, but another crash on that device could rule out a proposed fix.

The developer shared roughly nine to ten experimental builds over the investigation. Rather than continuing to revise code that looked suspicious, the developer removed one view or behavior at a time and had QA repeat the same workflow. Six or seven progressively narrowed builds isolated one file. Further tests identified a call to NSMutableAttributedString(data:options:documentAttributes:) with the document type set to HTML.

The call prepared legal and explanatory text near the bottom of each screen. The text itself was static, but it contained tappable links and phone numbers. The app converted the supplied HTML during asynchronous screen preparation, a path that did not guarantee main-thread execution.

Apple’s NSAttributedString documentation advises against invoking the importer on a background thread when the document type is HTML: the importer may try to synchronize with the main thread and time out. Apple also documents that WebKit handles HTML conversion. What looked at the call site like a straightforward transformation of Data therefore had a threading requirement that the surrounding code needed to enforce.

Enforcing the requirement across the app

The developer found every HTML-to-attributed-string conversion in the app and routed it through a shared rendering helper marked @MainActor. The UI code that used the result was also main-actor isolated. That kept the requirement attached to the conversion itself, without moving network requests, decoding or unrelated screen preparation onto the main actor.

The QA engineer repeated the workflow on the device that had exposed the earlier builds and could no longer trigger the crash. The team also tested both screens and their related features before merging the change into the hotfix branch.

After release, the developer reported that the specific crash signature no longer appeared at a statistically meaningful frequency. Exact production figures were confidential. Unlike the drop in the overall crash rate after the first hotfix, this result matched what QA observed on the affected device and what the developer had verified at every relevant call site.