ZHA USB stick won't configure on boot - sometimes

Preface, I was on a pi3+ using hassio (with working recorder and zha), but I have some extra pc components now and wanted to try to use it as a server instead. I used the 6 lines at the top of this page and then transferred over a snapshot of my pi right before I turned it off. I had to update my hassio version to latest, 0.92.2, to get nodered working.

When I first booted up, my zigbee devices would connect and work fine, but I also didn’t have my mariadb setup correctly for the recorder component. With the mariadb component failing during log, I would get these logs and it seems to pause startup until it decides to move on:

2019-05-06 09:08:37 INFO (MainThread) [homeassistant.setup] Setting up recorder
2019-05-06 09:08:38 ERROR (Recorder) [homeassistant.components.recorder] Error during connection setup: (MySQLdb._exceptions.OperationalError) (2005, "Unknown MySQL server host 'core-mariadb' (-2)")
(Background on this error at: http://sqlalche.me/e/e3q8) (retrying in 3 seconds)
2019-05-06 09:08:41 ERROR (Recorder) [homeassistant.components.recorder] Error during connection setup: (MySQLdb._exceptions.OperationalError) (2005, "Unknown MySQL server host 'core-mariadb' (-2)")
(Background on this error at: http://sqlalche.me/e/e3q8) (retrying in 3 seconds)
2019-05-06 09:08:44 ERROR (Recorder) [homeassistant.components.recorder] Error during connection setup: (MySQLdb._exceptions.OperationalError) (2005, "Unknown MySQL server host 'core-mariadb' (-2)")
(Background on this error at: http://sqlalche.me/e/e3q8) (retrying in 3 seconds)
2019-05-06 09:08:47 ERROR (Recorder) [homeassistant.components.recorder] Error during connection setup: (MySQLdb._exceptions.OperationalError) (2005, "Unknown MySQL server host 'core-mariadb' (-2)")
(Background on this error at: http://sqlalche.me/e/e3q8) (retrying in 3 seconds)
2019-05-06 09:08:47 WARNING (MainThread) [homeassistant.setup] Setup of recorder is taking over 10 seconds.
2019-05-06 09:08:50 ERROR (Recorder) [homeassistant.components.recorder] Error during connection setup: (MySQLdb._exceptions.OperationalError) (2005, "Unknown MySQL server host 'core-mariadb' (-2)")
(Background on this error at: http://sqlalche.me/e/e3q8) (retrying in 3 seconds)
2019-05-06 09:08:53 ERROR (Recorder) [homeassistant.components.recorder] Error during connection setup: (MySQLdb._exceptions.OperationalError) (2005, "Unknown MySQL server host 'core-mariadb' (-2)")
(Background on this error at: http://sqlalche.me/e/e3q8) (retrying in 3 seconds)
2019-05-06 09:08:56 ERROR (Recorder) [homeassistant.components.recorder] Error during connection setup: (MySQLdb._exceptions.OperationalError) (2005, "Unknown MySQL server host 'core-mariadb' (-2)")
(Background on this error at: http://sqlalche.me/e/e3q8) (retrying in 3 seconds)
2019-05-06 09:08:59 ERROR (Recorder) [homeassistant.components.recorder] Error during connection setup: (MySQLdb._exceptions.OperationalError) (2005, "Unknown MySQL server host 'core-mariadb' (-2)")
(Background on this error at: http://sqlalche.me/e/e3q8) (retrying in 3 seconds)
2019-05-06 09:09:02 ERROR (Recorder) [homeassistant.components.recorder] Error during connection setup: (MySQLdb._exceptions.OperationalError) (2005, "Unknown MySQL server host 'core-mariadb' (-2)")
(Background on this error at: http://sqlalche.me/e/e3q8) (retrying in 3 seconds)
2019-05-06 09:09:05 ERROR (Recorder) [homeassistant.components.recorder] Error during connection setup: (MySQLdb._exceptions.OperationalError) (2005, "Unknown MySQL server host 'core-mariadb' (-2)")
(Background on this error at: http://sqlalche.me/e/e3q8) (retrying in 3 seconds)

then eventually

2019-05-06 09:09:05 INFO (MainThread) [homeassistant.setup] Setting up zha
2019-05-06 09:09:05 INFO (MainThread) [homeassistant.setup] Setup of domain zha took 0.0 seconds.
2019-05-06 09:09:05 INFO (Wemo HTTP Thread) [pywemo.subscribe] Listening on port 8989
2019-05-06 09:09:05 INFO (MainThread) [homeassistant.setup] Setting up zwave
2019-05-06 09:09:05 INFO (MainThread) [homeassistant.setup] Setup of domain zwave took 0.0 seconds.

After I resolved my mariadb issues and restarted, I would get these logs:

2019-05-06 09:10:50 INFO (MainThread) [homeassistant.setup] Setting up recorder
2019-05-06 09:10:50 WARNING (Recorder) [homeassistant.components.recorder] Ended unfinished session (id=1 from 2019-05-06 04:12:57)
2019-05-06 09:10:50 INFO (MainThread) [homeassistant.setup] Setup of domain recorder took 0.2 seconds.

then:

2019-05-06 09:10:57 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry /dev/ttyUSB2 for zha
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/homeassistant/config_entries.py", line 309, in async_setup
    hass, self)
  File "/usr/local/lib/python3.7/site-packages/homeassistant/components/zha/__init__.py", line 99, in async_setup_entry
    await zha_gateway.async_initialize(config_entry)
  File "/usr/local/lib/python3.7/site-packages/homeassistant/components/zha/core/gateway.py", line 90, in async_initialize
    await self.application_controller.startup(auto_form=True)
  File "/usr/local/lib/python3.7/site-packages/bellows/zigbee/application.py", line 102, in startup
    await self.initialize()
  File "/usr/local/lib/python3.7/site-packages/bellows/zigbee/application.py", line 53, in initialize
    await e.reset()
  File "/usr/local/lib/python3.7/site-packages/bellows/ezsp.py", line 54, in reset
    await self._gw.reset()
  File "/usr/local/lib/python3.7/asyncio/tasks.py", line 423, in wait_for
    raise futures.TimeoutError()
concurrent.futures._base.TimeoutError

and slightly different logs for zwave (which does work):

2019-05-06 09:10:57 INFO (SyncWorker_8) [homeassistant.components.zwave] Starting Z-Wave network...
2019-05-06 09:10:57 INFO (SyncWorker_8) [openzwave] Start Openzwave network.
2019-05-06 09:10:57 INFO (Dummy-3) [openzwave] Driver ready using library Static Controller version Z-Wave 4.05
2019-05-06 09:10:57 INFO (Dummy-3) [openzwave] home_id 0xdb61cd93, controller node id is 1
2019-05-06 09:11:07 INFO (Dummy-3) [homeassistant.components.zwave] Z-Wave network is complete. All nodes on the network have been queried
2019-05-06 09:11:07 INFO (MainThread) [homeassistant.components.zwave] Z-Wave ready after 10 seconds

Now, in the configuration, if I comment out the mariadb connection and startup (using the default sqlite component), it still fails. What seems to happen, is if startup hangs for a bit because of the mariadb bad configuration, the zigbee usb device is given enough time to configure something in the background.

Here is my configuration for my usb stick:

zwave:
  usb_path: /dev/ttyUSB1

zha:
  usb_path: /dev/ttyUSB2
  database_path: /config/zigbee.db

With a working mariadb, I connected to the db, removed homeassistant db and let it be recreated in case there was some bad info, and also deleted the zigbee.db for the same reason, but neither seemed to have any effect on the issue.

I think this a a bug I am now experiencing this as well.

I submitted an issue on github: https://github.com/home-assistant/home-assistant/issues/23719