balena-os / balena-supervisor

Balena Supervisor: balena's agent on devices.
https://balena.io
Other
148 stars 63 forks source link

Supervisor patches device state with too large storage_usage value #1902

Open fisehara opened 2 years ago

fisehara commented 2 years ago

We have recently recorded API issues when the supervisor patches device/v2/<deviceUUID>/state with this request body:

{
    "dependent": {
        "apps": {}
    },
    "local": {
        "api_port": 48484,
        "api_secret": "[Filtered]",
        "apps": {},
        "cpu_id": "obfuscated",
        "cpu_temp": 81,
        "cpu_usage": 72,
        "ip_address": "obfuscated",
        "is_on__commit": "obfuscated",
        "is_undervolted": False,
        "logs_channel": None,
        "mac_address": "obfuscated",
        "memory_total": 962,
        "memory_usage": 630,
        "os_variant": "prod",
        "os_version": "balenaOS 2.73.1+rev1",
        "provisioning_progress": None,
        "provisioning_state": "",
        "status": "Idle",
        "storage_block_device": "/dev/mmcblk0",
        "storage_total": 27690,
        "storage_usage": 17592186015302,
        "supervisor_version": "12.4.6"
    }
}

The value "storage_usage": 17592186015302, is a valid javascript integer 2^53-1 but not a valid int-32 2^31-1. Moreover, the storage_usage shouldn't be greater than storage_total.

20k-ultra commented 2 years ago

This is the code responsible for calculating storage_total and storage_usage https://github.com/balena-os/balena-supervisor/blob/260737a570d303610768f7e6da8205e75e3024a3/src/lib/system-info.ts#L25-L52

There's probably something going on with the fact the total is set to a value whereas the usage is summed over a list of items which match a condition. Perhaps this condition has changed then so the sum is incorrect. Based on that usage we can confirm it's wrong since no device will have that much space. That's 17592.186015301999 petabytes.

fisehara commented 2 years ago

New occurrences from another device with different SV version:

 {
    "dependent": {
        "apps": {}
    },
    "local": {
        "api_port": 48484,
        "api_secret": "[Filtered]",
        "apps": {},
        "cpu_id": "obfuscated",
        "cpu_temp": 63,
        "cpu_usage": 30,
        "ip_address": "obfuscated",
        "is_on__commit": "obfuscated",
        "is_undervolted": False,
        "logs_channel": None,
        "mac_address": "obfuscated",
        "memory_total": 962,
        "memory_usage": 565,
        "os_variant": "prod",
        "os_version": "balenaOS 2.73.1+rev1",
        "provisioning_progress": None,
        "provisioning_state": "",
        "status": "Idle",
        "storage_block_device": "/dev/mmcblk0p6",
        "storage_total": 27690,
        "storage_usage": 17592186017246,
        "supervisor_version": "12.11.12"
    }
}