Remote schema download has no timeout, so a stalled connection hangs the run indefinitely
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 77/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- python
- Lĩnh vực
- cli, networking
Hướng nghiên cứu
Bắt đầu tại src/check_jsonschema/cachedownloader.py, ở _get_request, rồi theo dõi cách vòng lặp thử lại hiện có xử lý requests.RequestException. Thêm thời gian chờ có giới hạn cho kết nối và đọc vào yêu cầu, sau đó kiểm tra các bài kiểm tra về tải xuống schema từ xa và lỗi khi thử lại. Công việc hoàn tất khi một yêu cầu bị đình trệ đi đến bước xử lý thử lại và lỗi thay vì bị treo vô thời hạn.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Python
- Star
- 357
- Fork
- 74
- Merge trung bình
- 8 ngày 14 giờ
- Pull request đã merge (30 ngày)
- 3
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của python-jsonschema/check-jsonschema
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
python-jsonschema/check-jsonschema#737 · 2 bình luận ·
-
New vendored schemas: DatadogCó thể đã có người làm @lannuttia đã nhận 120 ngày trước. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
-
Feature Request: Support URL rewriteCó thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
-
Support ETag for cache validation when Last-Modified is unavailableCó thể đã có người làm @sirosen đã nhận 253 ngày trước. Đang mởenhancement
python-jsonschema/check-jsonschema#668 · 9 bình luận · 1 người được giao ·
-
Vendor multitool schemaCó thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 55/100
Tất cả issue của python-jsonschema/check-jsonschema
Issue tương tự
-
area:print-dispatch
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 92/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
area/geometry good first issue help wanted kind/doc-mismatch severity/4-minor
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Apich-Organization/rssn#295 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
-
chore claimed
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
schuyler/corvidae#1424 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày