Have Fun with Apple's Virtualization.Framework
One of the reasons I “love” Apple is the plethora of undocumented features that keep us on our toes. At Marathon Cloud, we rely on Apple’s Virtualization.Framework to launch virtual machines for testing purposes. Virtualization.Framework provides high-level Swift APIs for creating and managing virtual machines, making it a powerful tool for developers. We’ll explore more details about this framework and some of its inner workings in upcoming articles.
The Snapshot Problem
Our goal was to compare the performance of VMs with snapshots against those without them. We selected a series of client tests and ran them on both types of VMs. Everything seemed fine until, midway through the tests, our snapshotted VMs crashed. What was happening?
There was no documentation regarding any additional restrictions. The VM’s console logs didn’t reveal the root cause immediately, which made debugging particularly frustrating.
Finding the Root Cause
Further research led us to a discussion on Tart CLI (see the issue on GitHub), where users found that devices, including audio, cause snapshotted VMs to crash when used. Disabling these devices prevented crashes. Finally!
There were no crashes, but some video tests were still failing (though not crashing the VM). What now? Some video players require an audio device to display video, and our client uses such players. However, some players are more tolerant of audio issues. For instance, if you open YouTube in Google Chrome and play a video, it will work without issues, except for logs in the Console app indicating audio device problems.
Takeaway
So, we finally discovered what was crashing our VMs. But the disappointing point is that there is no official info about such corner cases. When working with Apple’s ecosystem, prepare for the unexpected. And if you think AI will replace engineers, think again. Not anytime soon.