Home Assistant crashing constantly at random times (aiohttp.server?)

Hi!

I’m having some strange problems with HA. Im running it on a
Raspberry Pi 4 Model B 4GB inside an Argon M2 case and booting it from an SSD.
At first I ran it from an SD card but once that crashed I switched to an SSD just assuming it was the end of life for the SD card, now I think it might be the same problem as Im having with this setup. The only common denominator is the PI.

The system crashes after random amounts of time after reboot. It can be instant, it can also take 3-4 hours.

It all starts with this error:

Logger: aiohttp.server
Source: components/media_player/__init__.py:987
First occurred: 14:35:03 (2 occurrences)
Last logged: 14:35:03

Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/aiohttp/connector.py", line 999, in _create_direct_connection
    File "/usr/local/lib/python3.9/site-packages/aiohttp/connector.py", line 999, in _create_direct_connection
      File "/usr/local/lib/python3.9/site-packages/aiohttp/connector.py", line 852, in _resolve_host
        File "/usr/local/lib/python3.9/site-packages/aiohttp/locks.py", line 38, in wait
          File "/usr/local/lib/python3.9/site-packages/aiohttp/connector.py", line 865, in _resolve_host
            File "/usr/local/lib/python3.9/site-packages/aiohttp/resolver.py", line 31, in resolve
              File "/usr/local/lib/python3.9/asyncio/base_events.py", line 856, in getaddrinfo
                  return await self.run_in_executor(
                    File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
                      File "/usr/local/lib/python3.9/socket.py", line 953, in getaddrinfo
                      socket.gaierror: [Errno -3] Try again
The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/aiohttp/web_protocol.py", line 422, in _handle_request
    File "/usr/local/lib/python3.9/site-packages/aiohttp/web_app.py", line 499, in _handle
      File "/usr/local/lib/python3.9/site-packages/aiohttp/web_middlewares.py", line 119, in impl
        File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 60, in security_filter_middleware
          File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 89, in forwarded_middleware
            File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 24, in request_context_middleware
              File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 78, in ban_middleware
                File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 144, in auth_middleware
                  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 135, in handle
                    File "/usr/src/homeassistant/homeassistant/components/media_player/__init__.py", line 1059, in get
                      File "/usr/src/homeassistant/homeassistant/components/media_player/__init__.py", line 497, in async_get_media_image
                        File "/usr/src/homeassistant/homeassistant/components/media_player/__init__.py", line 973, in _async_fetch_image_from_cache
                          File "/usr/src/homeassistant/homeassistant/components/media_player/__init__.py", line 987, in _async_fetch_image
                            File "/usr/local/lib/python3.9/site-packages/aiohttp/client.py", line 520, in _request
                              File "/usr/local/lib/python3.9/site-packages/aiohttp/connector.py", line 535, in connect
                                File "/usr/local/lib/python3.9/site-packages/aiohttp/connector.py", line 892, in _create_connection
                                  File "/usr/local/lib/python3.9/site-packages/aiohttp/connector.py", line 1011, in _create_direct_connection
                                  aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host i.scdn.co:443 ssl:default [Try again]                                 

Then this:

Logger: homeassistant.components.recorder
Source: components/recorder/__init__.py:841
Integration: Recorder (documentation, issues)
First occurred: 14:33:29 (34 occurrences)
Last logged: 14:35:09

SQLAlchemyError error processing event <Event time_changed[L]: now=2021-09-11T14:33:18.001679+02:00>: This connection is on an inactive transaction. Please rollback() fully before proceeding. (Background on this error at: http://sqlalche.me/e/14/8s2a)
SQLAlchemyError error processing event <Event time_changed[L]: now=2021-09-11T14:33:20.001626+02:00>: This connection is on an inactive transaction. Please rollback() fully before proceeding. (Background on this error at: http://sqlalche.me/e/14/8s2a)
SQLAlchemyError error processing event <Event time_changed[L]: now=2021-09-11T14:33:22.000739+02:00>: This connection is on an inactive transaction. Please rollback() fully before proceeding. (Background on this error at: http://sqlalche.me/e/14/8s2a)
SQLAlchemyError error processing event <Event time_changed[L]: now=2021-09-11T14:33:24.000766+02:00>: This connection is on an inactive transaction. Please rollback() fully before proceeding. (Background on this error at: http://sqlalche.me/e/14/8s2a)
SQLAlchemyError error processing event <Event time_changed[L]: now=2021-09-11T14:33:26.001988+02:00>: This connection is on an inactive transaction. Please rollback() fully before proceeding. (Background on this error at: http://sqlalche.me/e/14/8s2a)
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/recorder/__init__.py", line 632, in _process_one_event_or_recover
    File "/usr/src/homeassistant/homeassistant/components/recorder/__init__.py", line 752, in _process_one_event
      File "/usr/src/homeassistant/homeassistant/components/recorder/__init__.py", line 815, in _commit_event_session_or_retry
        File "/usr/src/homeassistant/homeassistant/components/recorder/__init__.py", line 841, in _commit_event_session
          File "/usr/local/lib/python3.9/site-packages/sqlalchemy/orm/session.py", line 1428, in commit
            File "/usr/local/lib/python3.9/site-packages/sqlalchemy/orm/session.py", line 836, in commit
              File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 2330, in commit
                File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 2529, in _do_commit
                  File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 544, in _invalid_transaction
                  sqlalchemy.exc.PendingRollbackError: This connection is on an inactive transaction.  Please rollback() fully before proceeding. (Background on this error at: http://sqlalche.me/e/14/8s2a)                 

Then this:

Logger: homeassistant.components.recorder
Source: components/recorder/__init__.py:818
Integration: Recorder (documentation, issues)
First occurred: 14:33:26 (35 occurrences)
Last logged: 14:35:09

Error in database connectivity during commit: Error executing query: (sqlite3.OperationalError) disk I/O error (Background on this error at: http://sqlalche.me/e/14/e3q8). (retrying in 3 seconds)

A picture from the HA cli:

I’ve tried a couple of reinstalls from scratch but the problems still persist.
I’ve deleted the DB file without success. I’m out of ideas of what might be wrong. Has this happened to anyone else? Any suggestions or input is greatly appreciated.

EDIT: After searching some more I found this topic: Error while loading page
I have the same problems and the log-files seems similar to mine.

Br

Kristian

Hi,

Did you solve your problem ?
I have same issue. I test with ssd directly connected on usb with a case, and no problem…
So the pb is the usb/usb jumper, or ssd card of argon m2…
But I can not test i dont agave and other jumper usb/usb.

Hi!

I “solved” it doing the same as you, connecting the SSD with a usb cable. So the bridge was the main problem. It still crashes from time to time though. I guess the problem now is either the SSD or the rpi. Eventually I’ll get s new rpi and see if that’s the problem, but haven’t gotten around to it.

Thanks,
I have do some test with a second argon box.
I have test with the new bridge, it work. But after… i have test again to be sure… and it work now with the old bridge… it’s crazy.
I think that the SSD is perhaps no correctly plug on motherboard of Argon.
I have do some test to stress the ssd with dd command to write on the disk. No problem.
I test Smart on SSD with Western digital tool, no problem.

So…

I had similar issue with a ADATA SSD.

This probably won’t help but, is it a power supply issue?

When I ran HA on RPI 4 I found it crashed every few days. I tried a different power supply and the crash frequency went down.

I’m now on a Dell micro PC and it hasn’t crashed since it went into production.

Right now I have the SSD directly connected to the pi with a cable and it still crashes, so not sure if it has to do with the argon case. I might be wrong though.

There might be something to this, it has crossed my mind. When I switched from the original charger to a more powerful (laptop charger) th frequency of crashes went down, but it still crashes. So might be a combination of a faulty rpi and the power supply. I’ll probably try the HA Amber when it’s in stock again and see if that solves the problem.