Remote schema download has no timeout, so a stalled connection hangs the run indefinitely
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 77/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- python
- 领域
- cli, networking
调研方向
从 src/check_jsonschema/cachedownloader.py 中的 _get_request 开始,追踪现有重试循环如何处理 requests.RequestException。为请求添加有界的连接和读取超时,然后检查涵盖远程 schema 下载和重试失败的测试。完成标准是:停滞的请求会进入重试和失败处理,而不是无限期挂起。
由索引模型根据 Issue 内容生成。
描述
Summary
_get_request in src/check_jsonschema/cachedownloader.py calls requests.get(file_url, stream=True) without a timeout. When the server accepts the TCP/TLS connection but then stops sending, the read blocks forever: no exception is raised, so the existing retry loop (num_retries = 2) never gets a chance to run, and the process (and any pre-commit run that includes the hook) hangs until it is killed.
Because the download runs on every invocation with a remote --schemafile (the cache is validated against the response's Last-Modified), a single stalled connection to the schema host is enough to hang a pre-commit run, even when a cached copy of the schema exists.
What I saw
check-jsonschema 0.38.0, run as a pre-commit hook:
- id: check-jsonschema
name: check taskfiles
args: [--schemafile, 'https://taskfile.dev/schema.json']
files: ^(Taskfile\.yaml|\.config/taskfiles/[^/]+\.yaml)$
The hook sat for over 10 minutes at 0% CPU, blocked in a socket read (/proc/<pid>/wchan was wait_woken), with one established connection to one of the host's two addresses. The same URL fetched with curl answered in about 0.25 s at that moment, so the stall was transient on one server connection, not an outage. Killing the process was the only way out.
The code on main (0.40.0) is unchanged here:
for _attempt in range(num_retries + 1):
try:
r = requests.get(file_url, stream=True)
except requests.RequestException as e:
...
Suggested fix
Pass a timeout to requests.get, for example timeout=(connect, read) such as (10, 30). A stalled read then raises requests.exceptions.ReadTimeout (a RequestException), which the existing loop already retries and, once retries are exhausted, turns into FailedDownloadError. The requests docs recommend setting a timeout on nearly all production requests for this reason: https://requests.readthedocs.io/en/latest/user/advanced/#timeouts
Optionally, the value could be configurable (a CLI flag or an environment variable) for slow networks, and on a download failure with an existing cache file the cached schema could be used with a warning, but the timeout alone would turn an indefinite hang into a bounded failure.
Happy to open a PR if that helps.
- 主要语言
- Python
- 星标
- 357
- 派生
- 74
- 平均合并
- 8 天 14 小时
- 30 天内合并 PR
- 3
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
python-jsonschema/check-jsonschema 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 77/100
python-jsonschema/check-jsonschema#737 · 2 条评论 ·
-
New vendored schemas: Datadog可能已有人在做 @lannuttia 于 120 天前认领。 未关闭
难度 3/5 1-2 天 新手友好度 35/100
-
Feature Request: Support URL rewrite可能重新可做 关联的 PR 已关闭且未合并。 未关闭
难度 4/5 3-5 天 新手友好度 48/100
-
Support ETag for cache validation when Last-Modified is unavailable可能已有人在做 @sirosen 于 253 天前认领。 未关闭enhancement
python-jsonschema/check-jsonschema#668 · 9 条评论 · 已指派 1 人 ·
-
Vendor multitool schema可能重新可做 关联的 PR 已关闭且未合并。 未关闭
难度 3/5 1-2 天 新手友好度 55/100
查看 python-jsonschema/check-jsonschema 的全部 Issue
相似的 Issue
-
area:print-dispatch
难度 2/5 1-3 小时 新手友好度 92/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
area/geometry good first issue help wanted kind/doc-mismatch severity/4-minor
难度 2/5 1-3 小时 新手友好度 68/100
Apich-Organization/rssn#295 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 88/100
-
chore claimed
难度 2/5 1-3 小时 新手友好度 72/100
schuyler/corvidae#1424 · 2 条评论 ·
维护者通常 1 天内回复