mx_tag: per-call Resolver (dns Resolver not thread-safe -- was deadlocking)

This commit is contained in:
justin 2026-06-14 21:26:38 -05:00
parent 5fd187a001
commit fd1522abee

View file

@ -32,15 +32,14 @@ DB_URL = os.getenv("DATABASE_URL", "")
# Fast, bounded MX resolution (the shared verifier uses an 8s+6s lifetime which
# is far too slow for bulk tagging across many dead domains). 3s, no A-fallback.
_resolver = dns.resolver.Resolver()
_resolver.lifetime = 3.0
_resolver.timeout = 3.0
# A dns.resolver.Resolver is NOT thread-safe, so each call uses its own.
def classify(domain: str) -> str:
r = dns.resolver.Resolver()
r.lifetime = 3.0
r.timeout = 3.0
try:
ans = _resolver.resolve(domain, "MX")
hosts = " ".join(str(r.exchange).rstrip(".") for r in ans).lower()
ans = r.resolve(domain, "MX")
hosts = " ".join(str(rr.exchange).rstrip(".") for rr in ans).lower()
except Exception:
return "no_mx"
if "protection.outlook" in hosts or "outlook.com" in hosts or "office365" in hosts: