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.
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.