Skip to content

Cannot schedule new futures after shutdown #3

@ivenhov

Description

@ivenhov

I'm not sure if this should be here on in predbat repo

After successful migration from appdaemon version to addon everything was working as expected.
Full restart of the HA caused the following though

2024-06-06 00:37:06.423475: Info: Start socket for url http://supervisor/core/api/websocket
2024-06-06 00:37:06.424256: Error: Web Socket exception in startup: cannot schedule new futures after shutdown
2024-06-06 00:37:06.424599: Error: Traceback (most recent call last):
  File "/config/predbat.py", line 15517, in socketLoop
    async with session.ws_connect(url) as websocket:
  File "/usr/local/lib/python3.10/dist-packages/aiohttp/client.py", line 1167, in __aenter__
    self._resp = await self._coro
  File "/usr/local/lib/python3.10/dist-packages/aiohttp/client.py", line 805, in _ws_connect
    resp = await self.request(
  File "/usr/local/lib/python3.10/dist-packages/aiohttp/client.py", line 562, in _request
    conn = await self._connector.connect(
  File "/usr/local/lib/python3.10/dist-packages/aiohttp/connector.py", line 540, in connect
    proto = await self._create_connection(req, traces, timeout)
  File "/usr/local/lib/python3.10/dist-packages/aiohttp/connector.py", line 901, in _create_connection
    _, proto = await self._create_direct_connection(req, traces, timeout)
  File "/usr/local/lib/python3.10/dist-packages/aiohttp/connector.py", line 1155, in _create_direct_connection
    hosts = await asyncio.shield(host_resolved)
  File "/usr/local/lib/python3.10/dist-packages/aiohttp/connector.py", line 874, in _resolve_host
    addrs = await self._resolver.resolve(host, port, family=self._family)
  File "/usr/local/lib/python3.10/dist-packages/aiohttp/resolver.py", line 33, in resolve
    infos = await self._loop.getaddrinfo(
  File "/usr/lib/python3.10/asyncio/base_events.py", line 863, in getaddrinfo
    return await self.run_in_executor(
  File "/usr/lib/python3.10/asyncio/base_events.py", line 821, in run_in_executor
    executor.submit(func, *args), loop=self)
  File "/usr/lib/python3.10/concurrent/futures/thread.py", line 167, in submit
    raise RuntimeError('cannot schedule new futures after shutdown')
RuntimeError: cannot schedule new futures after shutdown

2024-06-06 00:37:06.424742: Info: Start socket for url http://supervisor/core/api/websocket
2024-06-06 00:37:06.425475: Error: Web Socket exception in startup: cannot schedule new futures after shutdown
2024-06-06 00:37:06.425789: Error: Traceback (most recent call last):
  File "/config/predbat.py", line 15517, in socketLoop
    async with session.ws_connect(url) as websocket:
  File "/usr/local/lib/python3.10/dist-packages/aiohttp/client.py", line 1167, in __aenter__
    self._resp = await self._coro
  File "/usr/local/lib/python3.10/dist-packages/aiohttp/client.py", line 805, in _ws_connect
    resp = await self.request(
  File "/usr/local/lib/python3.10/dist-packages/aiohttp/client.py", line 562, in _request
    conn = await self._connector.connect(
  File "/usr/local/lib/python3.10/dist-packages/aiohttp/connector.py", line 540, in connect
    proto = await self._create_connection(req, traces, timeout)
  File "/usr/local/lib/python3.10/dist-packages/aiohttp/connector.py", line 901, in _create_connection
    _, proto = await self._create_direct_connection(req, traces, timeout)
  File "/usr/local/lib/python3.10/dist-packages/aiohttp/connector.py", line 1155, in _create_direct_connection
    hosts = await asyncio.shield(host_resolved)
  File "/usr/local/lib/python3.10/dist-packages/aiohttp/connector.py", line 874, in _resolve_host
    addrs = await self._resolver.resolve(host, port, family=self._family)
  File "/usr/local/lib/python3.10/dist-packages/aiohttp/resolver.py", line 33, in resolve
    infos = await self._loop.getaddrinfo(
  File "/usr/lib/python3.10/asyncio/base_events.py", line 863, in getaddrinfo
    return await self.run_in_executor(
  File "/usr/lib/python3.10/asyncio/base_events.py", line 821, in run_in_executor
    executor.submit(func, *args), loop=self)
  File "/usr/lib/python3.10/concurrent/futures/thread.py", line 167, in submit
    raise RuntimeError('cannot schedule new futures after shutdown')
RuntimeError: cannot schedule new futures after shutdown

This was happening in a tight loop.
Restart of the addon fixed the problem.

2024-06-06 00:37:07.037832: Info: Start socket for url http://supervisor/core/api/websocket
2024-06-06 00:37:16.090140: Loading apps.yaml
2024-06-06 00:37:16.118438: Predbat: Startup predbat
2024-06-06 00:37:16.148738: --------------- PredBat - update at 2024-06-06 00:35:00+01:00 with clock skew 0 minutes, minutes now 35
2024-06-06 00:37:16.148939: Config root is /config
2024-06-06 00:37:16.159226: Info: Connected to Home Assistant at http://supervisor/core
2024-06-06 00:37:16.159507: Creating task: <coroutine object HAInterface.socketLoop at 0x7f5b09b19930>
2024-06-06 00:37:16.160101: Info: Start socket for url http://supervisor/core/api/websocket
2024-06-06 00:37:16.160292: Info: Web Socket task started
2024-06-06 00:37:16.160619: Sanity check:
2024-06-06 00:37:16.160743: Sanity scan files in '/config' : ['predbat.py', 'predbat_dashboard.yaml', 'predbat_v7.22.2.zip', 'predbat.log.1', 'predbat_save', 'apps-brandnew.yaml', 'hass.py', 'apps.yaml', 'unzip', 'predbat.log']
2024-06-06 00:37:16.160803: Warn: unable to find /config/appdaemon.yaml skipping checks as maybe outside AppDaemon
2024-06-06 00:37:16.198117: Info: Web Socket active
...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions