Skip to content

Handle async proxy calls after event loop closes#730

Open
Wackymax wants to merge 1 commit into
zigpy:devfrom
Wackymax:agent/handle-closed-async-proxy
Open

Handle async proxy calls after event loop closes#730
Wackymax wants to merge 1 commit into
zigpy:devfrom
Wackymax:agent/handle-closed-async-proxy

Conversation

@Wackymax

Copy link
Copy Markdown

What changed

  • make coroutine methods exposed by ThreadsafeProxy consistently return an awaitable wrapper
  • treat calls made after the worker event loop has closed as a disconnected no-op
  • add a regression test covering an async proxy method after loop closure

Why

When a threaded EZSP transport loses its connection, the worker event loop can already be closed by the time ZHA asks bellows to disconnect. The existing proxy logs Attempted to use a closed event loop and returns plain None, even when the proxied method is asynchronous. The caller then attempts to await that value and raises:

TypeError: object NoneType can't be used in 'await' expression

This secondary cleanup exception can prevent Home Assistant's ZHA config-entry reload from recovering after the original transport failure.

The async wrapper now remains awaitable in every state. If the target loop is closed, awaiting it returns None, matching the existing disconnected/no-op behavior without raising a second exception.

Related reports:

Validation

  • added test_proxy_async_loop_closed
  • python -m pytest -q: 425 passed
  • git diff --check

@Wackymax
Wackymax marked this pull request as ready for review July 16, 2026 05:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant