Skip to main content

One post tagged with "dns-timeout"

View All Tags

Python urllib urlopen timeout Not Working on Windows: Fixing socket.getaddrinfo DNS Hangs

· 7 min read
Jaybee
AI & Robotics Engineer

While running a batch crawler across 194 official legal and government portals on Windows 11 (Python 3.12.6), our script froze completely on the 14th URL. Even though every request explicitly passed timeout=8 to urllib.request.urlopen and set socket.setdefaulttimeout(8) at startup, the process hung for over three minutes without raising TimeoutError or urllib.error.URLError.

This post documents the exact stack trace when interrupting the hang, why urllib.request.urlopen and requests.get timeouts fail during Windows socket.getaddrinfo DNS resolution, the three workarounds that failed first, and the production fix that brought batch execution down from an indefinite hang to a deterministic 4-second ceiling per host.