HA Core task exit with error on server restart via UI

Hi. Please help me, a week ago my system became unstable. I’m on HA Core 2022.2.4, Python 3.9.7 and Raspberry OS Buster on a Pi4 (armv7l).
When I restart HA server from the UI “something bad happens”, and I need to manually start it from the terminal.
I’ve launched hass in debug mode and when I restart the server from the UI here are the console messages that hass outputs:

2022-02-09 10:25:42 ERROR (MainThread) [homeassistant] Error doing job: Future exception was never retrieved:   File "/srv/homeassistant/bin/hass", line 8, in <module>
    sys.exit(main())
  File "/srv/homeassistant/lib/python3.9/site-packages/homeassistant/__main__.py", line 191, in main
    exit_code = runner.run(runtime_conf)
  File "/srv/homeassistant/lib/python3.9/site-packages/homeassistant/runner.py", line 119, in run
    return loop.run_until_complete(setup_and_run_hass(runtime_config))
  File "/usr/local/lib/python3.9/asyncio/base_events.py", line 629, in run_until_complete
    self.run_forever()
  File "/usr/local/lib/python3.9/asyncio/base_events.py", line 596, in run_forever
    self._run_once()
  File "/usr/local/lib/python3.9/asyncio/base_events.py", line 1882, in _run_once
    handle._run()
  File "/usr/local/lib/python3.9/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/srv/homeassistant/lib/python3.9/site-packages/homeassistant/core.py", line 965, in _onetime_listener
    self._hass.async_run_job(listener, event)
  File "/srv/homeassistant/lib/python3.9/site-packages/homeassistant/core.py", line 569, in async_run_job
    return self.async_run_hass_job(HassJob(target), *args)
  File "/srv/homeassistant/lib/python3.9/site-packages/homeassistant/core.py", line 529, in async_run_hass_job
    return self.async_add_hass_job(hassjob, *args)
  File "/srv/homeassistant/lib/python3.9/site-packages/homeassistant/core.py", line 445, in async_add_hass_job
    task = self.loop.run_in_executor(
  File "/usr/local/lib/python3.9/asyncio/base_events.py", line 813, in run_in_executor
    return futures.wrap_future(
  File "/usr/local/lib/python3.9/asyncio/futures.py", line 412, in wrap_future
    new_future = loop.create_future()
  File "/usr/local/lib/python3.9/asyncio/base_events.py", line 424, in create_future
    return futures.Future(loop=self)
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/homeassistant/.homeassistant/custom_components/localtuya/__init__.py", line 218, in _shutdown
    discovery.close()
  File "/home/homeassistant/.homeassistant/custom_components/localtuya/discovery.py", line 59, in close
    transport.close()
  File "/usr/local/lib/python3.9/asyncio/selector_events.py", line 700, in close
    self._loop.call_soon(self._call_connection_lost, None)
  File "/usr/local/lib/python3.9/asyncio/base_events.py", line 748, in call_soon
    self._check_thread()
  File "/usr/local/lib/python3.9/asyncio/base_events.py", line 785, in _check_thread
    raise RuntimeError(
RuntimeError: Non-thread-safe operation invoked on an event loop other than the current one
Found 2 non-daemonic threads.

I haven’t found any solution by googling. Maybe it could be an issue related to the python version I’m switched to? Said, I have installed hass in python 3.9.7 more than two months ago and the issue has happened only few days ago.
Thanks for your help!

There is an open issue about this on github.
Please report your findings there too.

Done, thanks for your reply