Encrypted CoreML model load failed with error : Failed to set up decrypt context for /path/to/xxx.mlmodelc. error:-42905"

Hi there. We use coreml for image processing, and we have many models, each one produces a different effect.

However, this error sometimes occurs on some devices. No idea when and how. But once it happens, it keeps failing on the device.

At this point, these will solve the issue:

  1. Uninstall and reinstall the app. It works fine for a while, but the same error soon occurs again.
  2. Reboot the device. It work fine for a longer time than reinstall.

I tried repeatedly loading and unloading the model in a loop, but I couldn't reproduce the issue.

If the model loads successfully the first time the application starts up, it will continue to load successfully for the remainder of the application's lifecycle.

If I repeatedly launch the app, load the model, and then force-close the app—after doing this a few hundred times—the problem will eventually occur.

The following are two similar questions:

https://developer.apple.com/forums/thread/678599

https://developer.apple.com/forums/thread/740731

A previous reply stated that "it typically means there is a leak in the system," but since the app has already been terminated, the resources it was using should have been automatically reclaimed by the system.

This issue has been a problem for a long time; it does indeed appear to be a system-level bug. This uncertainty and unreliability can lead to user churn.

Confirmed, If I manully release MLModel in sceneDidDisconnect, and then the problem disappear.

I'm convinced this is a system-level bug; if the app crashes or killed, it causes something to leak in the system, that makes absolutely no sense.

Although I temporarily resolved the issue using sceneDidDisconnect. However, sceneDidDisconnect is not a reliable cleanup point because it is not guaranteed to be invoked in many real-world termination scenarios.

For example, the callback may not be called when the app is force-terminated by Xcode Stop, killed by the system due to memory pressure (Jetsam), terminated by the watchdog, crashes unexpectedly, or is otherwise killed before scene teardown occurs.

I have also reproduced the -42905 failure by repeatedly launching the app, loading the encrypted model, and then pressing Xcode's Stop button. In that scenario the process is terminated without a guaranteed opportunity to execute sceneDidDisconnect, yet the failure still accumulates over time. This suggests that cleanup cannot rely solely on application-level lifecycle callbacks.

This must be a system bug; it’s hard to believe this issue has persisted for over four years and still hasn’t been resolved.

@Apple

Fine, @ not working 🙃🙃🙃

Encrypted CoreML model load failed with error : Failed to set up decrypt context for /path/to/xxx.mlmodelc. error:-42905"
 
 
Q