Skip to content

Commit 3d1969a

Browse files
authored
fix: Add timeout when downloading inventories (10 seconds)
Issue-819: #819
1 parent a0c47b9 commit 3d1969a

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

src/mkdocstrings/_internal/download.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
# Regex pattern for an environment variable in the form ${ENV_VAR}.
2020
_ENV_VAR_PATTERN = re.compile(r"\$\{([A-Za-z_][A-Za-z0-9_]*)\}")
2121

22+
# Timeout in seconds for downloading.
23+
_TIMEOUT = 10
24+
2225

2326
def _download_url_with_gz(url: str) -> bytes:
2427
url, auth_header = _extract_auth_from_url(url)
@@ -27,7 +30,7 @@ def _download_url_with_gz(url: str) -> bytes:
2730
url,
2831
headers={"Accept-Encoding": "gzip", "User-Agent": "mkdocstrings/0.15.0", **auth_header},
2932
)
30-
with urllib.request.urlopen(req) as resp: # noqa: S310
33+
with urllib.request.urlopen(req, timeout=_TIMEOUT) as resp: # noqa: S310
3134
content: BinaryIO = resp
3235
if "gzip" in resp.headers.get("content-encoding", ""):
3336
content = gzip.GzipFile(fileobj=resp) # ty: ignore[invalid-assignment]

0 commit comments

Comments
 (0)