Skip to content

Commit d684360

Browse files
elmuratofrenck
authored andcommitted
Fix blocking open in Minecraft Server (home-assistant#146820)
Fix blocking open by dnspython
1 parent 01a133a commit d684360

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

homeassistant/components/minecraft_server/__init__.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import logging
66
from typing import Any
77

8+
import dns.asyncresolver
89
import dns.rdata
910
import dns.rdataclass
1011
import dns.rdatatype
@@ -22,20 +23,23 @@
2223
_LOGGER = logging.getLogger(__name__)
2324

2425

25-
def load_dnspython_rdata_classes() -> None:
26-
"""Load dnspython rdata classes used by mcstatus."""
26+
def prevent_dnspython_blocking_operations() -> None:
27+
"""Prevent dnspython blocking operations by pre-loading required data."""
28+
29+
# Blocking import: https://github.com/rthalley/dnspython/issues/1083
2730
for rdtype in dns.rdatatype.RdataType:
2831
if not dns.rdatatype.is_metatype(rdtype) or rdtype == dns.rdatatype.OPT:
2932
dns.rdata.get_rdata_class(dns.rdataclass.IN, rdtype) # type: ignore[no-untyped-call]
3033

34+
# Blocking open: https://github.com/rthalley/dnspython/issues/1200
35+
dns.asyncresolver.get_default_resolver()
36+
3137

3238
async def async_setup_entry(
3339
hass: HomeAssistant, entry: MinecraftServerConfigEntry
3440
) -> bool:
3541
"""Set up Minecraft Server from a config entry."""
36-
37-
# Workaround to avoid blocking imports from dnspython (https://github.com/rthalley/dnspython/issues/1083)
38-
await hass.async_add_executor_job(load_dnspython_rdata_classes)
42+
await hass.async_add_executor_job(prevent_dnspython_blocking_operations)
3943

4044
# Create coordinator instance and store it.
4145
coordinator = MinecraftServerCoordinator(hass, entry)

0 commit comments

Comments
 (0)