fix: tell a local DNS outage from a gone host

This commit is contained in:
Abdessamad Derraz committed 2026-10-17 01:47:26 +02:00
1 parent cd4a9143f7
commit 08aa0beb22
2 files changed
+36 -6

No files matched your search

+18 -1
View File
@@ -208,12 +208,29 @@ def _host_is_unresolvable(exc: BaseException) -> bool:
if seen is None:
break
if isinstance(seen, socket.gaierror):
return True
# A resolver that answers nothing at all is the local network:
# every profile would read as gone, and the sweep would report
# nothing to review while it reviewed nothing.
return seen.errno == socket.EAI_NONAME and _resolver_answers()
nested = getattr(seen, "reason", None)
seen = nested if isinstance(nested, BaseException) else seen.__cause__
return False
# A name every forge call depends on: if it does not resolve, the fault is
# local and no host can be declared gone.
RESOLVER_PROBE = "github.com"
def _resolver_answers() -> bool:
"""Whether name resolution works here at all. Replaced in tests."""
try:
socket.getaddrinfo(RESOLVER_PROBE, 443)
except OSError:
return False
return True
def _fetch(url: str, accept_json: bool = False) -> bytes | None:
"""Body of a GET, or None on 404.