tomaae / homeassistant-truenas

TrueNAS integration for Home Assistant
Apache License 2.0
181 stars 16 forks source link

[Bug] "division by zero" error #152

Closed frakoch closed 2 weeks ago

frakoch commented 4 months ago

Describe the issue

I just updated to master via HACS to test out the new version and immediately found this in the logs (+ the integration not loading). I have a pool that is offline, which might be the cause of this, but nevertheless the values should be sanitized before using them.

How to reproduce the issue

not sure, I suppose offlining a pool

Expected behavior

component should initialize and run :)

Screenshots

Software versions

Diagnostics data

Logger: custom_components.truenas.coordinator
Source: helpers/update_coordinator.py:315
Integration: TrueNAS (Dokumentation, Issues)

Unexpected error fetching BRAIN data: float division by zero
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 315, in _async_refresh
    self.data = await self._async_update_data()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/truenas/coordinator.py", line 104, in _async_update_data
    await self.hass.async_add_executor_job(self.get_pool)
  File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/truenas/coordinator.py", line 782, in get_pool
    self.ds["pool"][uid]["available_gib"]
ZeroDivisionError: float division by zero

Traceback/Error logs

Additional context

tomaae commented 4 months ago

I will need debugs to see what happened there. Seems like you truenas is sending faulty data.

frakoch commented 4 months ago

there you go, hope it helps: https://paste.kodi.tv/bunanonine.kodi

It seems that it is related to the boot-pool? At least the exception seems to occur when processing the boot-pool

edit: I migrated to TrueNAS Dragonfish-24.04.0 in the meantime. The debug is from the API responses of this version edit2: I also switched to your beta release now, since I read in the other issue that installing the main GH branch seems to fail in times with HACS

tomaae commented 4 months ago

It is actually caused by offline pool. How did you took the pool offline? I will fix this when I get home.

'id': 7, 'name': 'tank', 'guid': 'XXX', 'path': '/mnt/tank', 'status': 'OFFLINE',
frakoch commented 4 months ago

HDDs are temporarily unplugged. Didn't want to deal with TrueNAS complaining about SMB shares pointing to a missing pool, permissions and what not

tomaae commented 4 months ago

ok, that should be easy to simulate in VM

frakoch commented 4 months ago

thanks. I can confirm it's working now. The only thing "missing" is that the sensor sensor.NAME_datasets_POOLNAME seems not to get created in this state, while all other related sensors (ZFS health etc) are still present (even though empty). Not a big thing, just something I noticed.

tomaae commented 4 months ago

do you mean size sensor for tank pool?

frakoch commented 4 months ago

yeah. In my case I see sensor.brain_datasets_data (and all its child datasets) but no sensor.brain_datasets_tank. However sensor.brain_system_tank_free f.e. is there (although 0/undefined ofc)

tomaae commented 4 months ago

I will look into it

github-actions[bot] commented 4 weeks ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

github-actions[bot] commented 2 weeks ago

This issue was closed because it has been stalled for 5 days with no activity.