OperationalError + InvalidRequestError + OSError = unstable system

After updating from 0.112 to 0.114.4 the system becomes unstable.
It hangs after a couple of hours (sometimes 10 hours, sometimes 3).
I’ve added Sentry two days ago and I see 31 issues and some of them occurred 51 times :man_facepalming:

I’ve put most of them in this issue

I have a very simple setup:
Pi 3 running on 5V3A Mean Well power supply + 32GB SD card.
3 DS18B20 sensors and 8 relays (with external power supply).

The system worked fine until the last update.
I don’t know how to debug and solve this problem.
Should I replace the SD Card? Maybe I should replace Raspberry Pi?

The system is controlling the heating system in my parent’s house, yesterday it crashed when the heating was turned on. The system wasn’t able to close the valves and turn off the pump. Because of that, my parents had 29 degrees. Fortunately, they were in the house and after a hard reset, the system was working again.
I don’t want to think about what could happen if they were on vacation for a week or two.

Which is why I only turn my heating on or off and leave the thermostat setting to the physical thermostat on the heaters.

As I wrote before I have a very simple setup.
I don’t have physical thermostats, I control the temperature with DS18B20, relays, and Home Assistant.
If I would like to replace all of that with physical thermostats I can get rid of Home Assistant right away, because this is the main function it is doing.
But that’s not the point :slight_smile: I really like HA, the flexibility it has and I still want to use it.
But because of such issues, it is hard to convince anyone (including my parents and myself) that the system is rock-solid and safe to use.

Another crash :confused:

Logger: homeassistant.helpers.entity
Source: components/filesize/sensor.py:50
First occurred: 10:27:22 (95 occurrences)
Last logged: 11:14:22

Update for sensor.home_assistant_v2_db fails
Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/helpers/entity.py”, line 263, in async_update_ha_state
File “/usr/src/homeassistant/homeassistant/helpers/entity.py”, line 456, in async_device_update
File “/usr/local/lib/python3.8/concurrent/futures/thread.py”, line 57, in run
File “/usr/src/homeassistant/homeassistant/components/filesize/sensor.py”, line 50, in update
OSError: [Errno 5] I/O error: ‘/config/home-assistant_v2.db’

Logger: homeassistant
Source: helpers/storage.py:225
First occurred: 10:27:26 (8 occurrences)
Last logged: 11:12:26

Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/helpers/restore_state.py”, line 175, in _async_dump_states
File “/usr/src/homeassistant/homeassistant/helpers/restore_state.py”, line 161, in async_dump_states
File “/usr/src/homeassistant/homeassistant/helpers/storage.py”, line 143, in async_save
File “/usr/src/homeassistant/homeassistant/helpers/storage.py”, line 216, in _async_handle_write_data
File “/usr/local/lib/python3.8/concurrent/futures/thread.py”, line 57, in run
File “/usr/src/homeassistant/homeassistant/helpers/storage.py”, line 225, in _write_data
File “/usr/local/lib/python3.8/os.py”, line 223, in makedirs
OSError: [Errno 5] I/O error: ‘/config/.storage’

Logger: aiohttp.server
Source: components/recorder/util.py:80
First occurred: 11:11:14 (8 occurrences)
Last logged: 11:11:35

Error handling request
Traceback (most recent call last):
File “/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/base.py”, line 2339, in _wrap_pool_connect
File “/usr/local/lib/python3.8/site-packages/sqlalchemy/pool/base.py”, line 364, in connect
File “/usr/local/lib/python3.8/site-packages/sqlalchemy/pool/base.py”, line 778, in _checkout
File “/usr/local/lib/python3.8/site-packages/sqlalchemy/pool/base.py”, line 495, in checkout
File “/usr/local/lib/python3.8/site-packages/sqlalchemy/pool/impl.py”, line 239, in _do_get
File “/usr/local/lib/python3.8/site-packages/sqlalchemy/pool/base.py”, line 309, in _create_connection
File “/usr/local/lib/python3.8/site-packages/sqlalchemy/pool/base.py”, line 440, in init
File “/usr/local/lib/python3.8/site-packages/sqlalchemy/pool/base.py”, line 661, in _connect
File “/usr/local/lib/python3.8/site-packages/sqlalchemy/util/langhelpers.py”, line 68, in exit
File “/usr/local/lib/python3.8/site-packages/sqlalchemy/util/compat.py”, line 178, in raise

File “/usr/local/lib/python3.8/site-packages/sqlalchemy/pool/base.py”, line 656, in __connect
File “/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/strategies.py”, line 114, in connect
File “/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/default.py”, line 493, in connect
sqlite3.OperationalError: unable to open database file

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File “/usr/local/lib/python3.8/site-packages/aiohttp/web_protocol.py”, line 418, in start
File “/usr/local/lib/python3.8/site-packages/aiohttp/web_app.py”, line 458, in _handle
File “/usr/local/lib/python3.8/site-packages/aiohttp/web_middlewares.py”, line 119, in impl
File “/usr/src/homeassistant/homeassistant/components/http/real_ip.py”, line 39, in real_ip_middleware
File “/usr/src/homeassistant/homeassistant/components/http/ban.py”, line 73, in ban_middleware
File “/usr/src/homeassistant/homeassistant/components/http/auth.py”, line 127, in auth_middleware
File “/usr/src/homeassistant/homeassistant/components/http/view.py”, line 129, in handle
File “/usr/src/homeassistant/homeassistant/components/history/init.py”, line 499, in get
File “/usr/local/lib/python3.8/concurrent/futures/thread.py”, line 57, in run
File “/usr/src/homeassistant/homeassistant/components/history/init.py”, line 525, in _sorted_significant_states_json
File “/usr/src/homeassistant/homeassistant/components/history/init.py”, line 141, in _get_significant_states
File “/usr/src/homeassistant/homeassistant/components/recorder/util.py”, line 80, in execute
File “/usr/local/lib/python3.8/site-packages/sqlalchemy/ext/baked.py”, line 445, in iter
File “/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/query.py”, line 3524, in _execute_and_instances
File “/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/query.py”, line 3539, in _get_bind_args
File “/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/query.py”, line 3518, in _connection_from_session
File “/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/session.py”, line 1138, in connection
File “/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/session.py”, line 1146, in _connection_for_bind
File “/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/session.py”, line 433, in _connection_for_bind
File “/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/base.py”, line 2305, in _contextual_connect
File “/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/base.py”, line 2342, in _wrap_pool_connect
File “/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/base.py”, line 1584, in handle_dbapi_exception_noconnection
File “/usr/local/lib/python3.8/site-packages/sqlalchemy/util/compat.py”, line 178, in raise

File “/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/base.py”, line 2339, in _wrap_pool_connect
File “/usr/local/lib/python3.8/site-packages/sqlalchemy/pool/base.py”, line 364, in connect
File “/usr/local/lib/python3.8/site-packages/sqlalchemy/pool/base.py”, line 778, in _checkout
File “/usr/local/lib/python3.8/site-packages/sqlalchemy/pool/base.py”, line 495, in checkout
File “/usr/local/lib/python3.8/site-packages/sqlalchemy/pool/impl.py”, line 239, in _do_get
File “/usr/local/lib/python3.8/site-packages/sqlalchemy/pool/base.py”, line 309, in _create_connection
File “/usr/local/lib/python3.8/site-packages/sqlalchemy/pool/base.py”, line 440, in init
File “/usr/local/lib/python3.8/site-packages/sqlalchemy/pool/base.py”, line 661, in _connect
File “/usr/local/lib/python3.8/site-packages/sqlalchemy/util/langhelpers.py”, line 68, in exit
File “/usr/local/lib/python3.8/site-packages/sqlalchemy/util/compat.py”, line 178, in raise

File “/usr/local/lib/python3.8/site-packages/sqlalchemy/pool/base.py”, line 656, in __connect
File “/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/strategies.py”, line 114, in connect
File “/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/default.py”, line 493, in connect
sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) unable to open database file
(Background on this error at: Error Messages — SQLAlchemy 1.3 Documentation)

Logger: homeassistant.components.recorder.util
Source: components/recorder/util.py:36
Integration: Recorder (documentation, issues)
First occurred: 11:11:14 (8 occurrences)
Last logged: 11:11:35

Error executing query: (sqlite3.OperationalError) unable to open database file (Background on this error at: Error Messages — SQLAlchemy 1.3 Documentation)

Logger: aiohttp.server
Source: components/http/static.py:39
First occurred: 11:20:51 (36 occurrences)
Last logged: 11:21:43

Error handling request
Traceback (most recent call last):
File “/usr/local/lib/python3.8/site-packages/aiohttp/web_protocol.py”, line 418, in start
File “/usr/local/lib/python3.8/site-packages/aiohttp/web_app.py”, line 458, in _handle
File “/usr/local/lib/python3.8/site-packages/aiohttp/web_middlewares.py”, line 119, in impl
File “/usr/src/homeassistant/homeassistant/components/http/real_ip.py”, line 39, in real_ip_middleware
File “/usr/src/homeassistant/homeassistant/components/http/ban.py”, line 73, in ban_middleware
File “/usr/src/homeassistant/homeassistant/components/http/auth.py”, line 127, in auth_middleware
File “/usr/src/homeassistant/homeassistant/components/http/static.py”, line 39, in _handle
File “/usr/local/lib/python3.8/pathlib.py”, line 1403, in is_dir
File “/usr/local/lib/python3.8/pathlib.py”, line 1194, in stat
OSError: [Errno 5] I/O error: ‘/usr/local/lib/python3.8/site-packages/hass_frontend/static/mdi/836998573a5d3d0c4d80f23e8657af349b083809.json’

Another crash. Thanks to Sentry I have a list of errors and their number.
InvalidRequestError - 212 times, OSError - 155 times, Database error 89 times.
The data is only from the last 24 hours!