Skip to content

Fix event-loop blocking in has_v2_api by using asyncio.timeout - #640

Open
Livyon wants to merge 1 commit into
homewizard:mainfrom
Livyon:patch-1
Open

Livyon wants to merge 1 commit into
homewizard:mainfrom
Livyon:patch-1

Conversation

@Livyon

@Livyon Livyon commented Oct 14, 2026

Copy link
Copy Markdown

Proposed change

This PR replaces the native aiohttp timeout in has_v2_api with Python's strict asyncio.timeout().

Currently, when a device drops off the network or crashes, the mDNS/Zeroconf discovery triggers has_v2_api in the background. Because it instantiates an unmanaged ClientSession using aiohttp's internal timeout parameter, DNS resolution or socket creation can occasionally fail to yield, blocking the main asyncio event-loop of the consuming application (like Home Assistant) for several seconds.

By wrapping the call in asyncio.timeout(5.0), we guarantee immediate task cancellation if the network hangs, keeping the core event-loop strictly non-blocking.

Note: The main _request methods in V1 and V2 already use asyncio.timeout correctly. This patch brings has_v2_api in line with the rest of the library.

Type of change

  • Bugfix
  • New feature
  • Breaking change

Refactor API call to include timeout handling.
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