Remote schema download has no timeout, so a stalled connection hangs the run indefinitely
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 77/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- python
- Domain
- cli, networking
Research direction
Start in src/check_jsonschema/cachedownloader.py at _get_request and trace how its existing retry loop handles requests.RequestException. Add a bounded connect and read timeout to the request, then check the tests covering remote schema downloads and retry failures. Done means a stalled request reaches the retry and failure handling instead of hanging indefinitely.
Written by the indexing model from the issue text.
Description
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.
- Dominant language
- Python
- Stars
- 357
- Forks
- 74
- Avg merge
- 8d 14h
- Merged PRs (30d)
- 3
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from python-jsonschema/check-jsonschema
-
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
python-jsonschema/check-jsonschema#737 · 2 comments ·
-
New vendored schemas: DatadogPossibly taken @lannuttia claimed this 120 days ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 35/100
-
Feature Request: Support URL rewriteMay be free again A pull request for this issue was closed without being merged. Open
Difficulty 4/5 3-5 days Newbie friendliness 48/100
-
Support ETag for cache validation when Last-Modified is unavailablePossibly taken @sirosen claimed this 253 days ago. Openenhancement
python-jsonschema/check-jsonschema#668 · 9 comments · 1 assignee ·
-
Vendor multitool schemaMay be free again A pull request for this issue was closed without being merged. Open
Difficulty 3/5 1-2 days Newbie friendliness 55/100
All issues in python-jsonschema/check-jsonschema
Similar issues
-
area:print-dispatch
Difficulty 2/5 1-3 hours Newbie friendliness 92/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
area/geometry good first issue help wanted kind/doc-mismatch severity/4-minor
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Apich-Organization/rssn#295 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
chore claimed
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
schuyler/corvidae#1424 · 2 comments ·
Maintainers usually reply within 1 day