balena-io-modules / balena-preload

Script for preloading containers onto balena device images
https://www.balena.io/
Apache License 2.0
35 stars 8 forks source link

Inactive devices left behind if preloading fails between temporary device creation and deletion #270

Open pdcastro opened 2 years ago

pdcastro commented 2 years ago

As originally reported at: https://forums.balena.io/t/issues-using-balena-preload/352835

I gather that the _getState function temporarily creates a device in order to grab a copy of the balena supervisor's target state for the fleet, which is then stored at /mnt/data/apps.json for consumption by the supervisor when the preloaded image is first booted (so the supervisor knows straight away what app images to download). However, if any operation fails (including network timeouts) between temporary device creation and deletion, the temporary device is left behind and can be listed as "inactive" in the fleet's web dashboard.

The code is missing a try/finally block to ensure deletion of the temporary device if any operation fails. Even then it is not guaranteed that the device will be deleted because the API backend may be facing issues, so consider also an improvement by which the target state can be obtained without the need of creating temporary devices.

jellyfish-bot commented 2 years ago

[pdcastro] This issue has attached support thread https://jel.ly.fish/aae91532-699c-4059-9a2b-7f685b619c16