mx_tag: per-call Resolver (dns Resolver not thread-safe -- was deadlocking)
This commit is contained in:
parent
5fd187a001
commit
fd1522abee
1 changed files with 6 additions and 7 deletions
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue