iOS Development
Hidden Threading Bug in iOS App Crashes: How Fault Isolation Revealed Foundation's HTML Import Constraint
A vague SIGBUS crash in production became solvable only when controlled experiments and one reproducible device replaced guesswork, exposing an undocumented threading requirement in NSAttributedString's HTML import.
InfoQ
An iOS application experienced mysterious production crashes that resisted all attempts at local reproduction. The crash reports showed a low-level SIGBUS signal and Foundation frames but no clear code path. What followed was an investigation that transformed debugging into systematic experimentation—and uncovered a subtle but critical threading contract buried deep inside Foundation's attributed string handling.
The Unreproducible Crash#
The failures appeared sporadically in a large consumer app, hitting only some users under unpredictable conditions. Neither developers nor QA could trigger it consistently by following the documented flow. The crash report offered clues—Foundation's attributed string processing appeared in the stack—but pointed to no obvious Swift code defect.
Initial attempts followed the usual pattern: enabling Zombie Objects, adding breakpoints, tightening object ownership, and clarifying synchronization. The team made defensive improvements throughout the affected screens and pushed a hotfix. The aggregate crash rate dropped noticeably.
Yet the same crash signature kept appearing in production. The improvement was real but not because the underlying defect was fixed—it was because timing-sensitive concurrency bugs can shift their frequency without disappearing.
From Guesswork to Testable Experiments#
The breakthrough came when a QA engineer discovered she could trigger the crash by repeating the affected flow on her personal device. It remained intermittent—sometimes needing four or five attempts—but was finally reproducible. That one device transformed the investigation from forensic speculation into controlled engineering.
Instead of reasoning about which code looked suspicious, the team inverted the question: which code absolutely had to stay for the crash to survive? By removing one view or section at a time, building new versions, and testing on the reproducible device, the team narrowed the problem down through systematic elimination.
After six or seven experimental builds, the failure isolated to a single file. Within that file, the problem concentrated further until it landed on one seemingly innocuous operation: HTML-to-attributed-string conversion.
The Ordinary Code That Hid a Threading Violation#
The problematic line looked straightforward:

