Remote schema download has no timeout, so a stalled connection hangs the run indefinitely
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 77/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- python
- Ambito
- cli, networking
Direzione di ricerca
Inizia in src/check_jsonschema/cachedownloader.py, in _get_request, e segui il modo in cui il ciclo di tentativi esistente gestisce requests.RequestException. Aggiungi alla richiesta un timeout limitato per la connessione e la lettura, poi controlla i test che coprono i download di schemi remoti e gli errori dei tentativi. Il lavoro è completato quando una richiesta bloccata raggiunge la gestione dei tentativi e degli errori invece di restare in attesa all’infinito.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- Python
- Stelle
- 357
- Fork
- 74
- Merge medio
- 8g 14h
- PR unite (30g)
- 3
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di python-jsonschema/check-jsonschema
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 77/100
python-jsonschema/check-jsonschema#737 · 2 commenti ·
-
New vendored schemas: DatadogForse già presa @lannuttia l’ha presa 120 giorni fa. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
-
Feature Request: Support URL rewriteForse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
-
Support ETag for cache validation when Last-Modified is unavailableForse già presa @sirosen l’ha presa 253 giorni fa. Apertaenhancement
python-jsonschema/check-jsonschema#668 · 9 commenti · 1 assegnatario ·
-
Vendor multitool schemaForse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 55/100
Tutte le issue di python-jsonschema/check-jsonschema
Issue simili
-
area:print-dispatch
Difficoltà 2/5 1-3 ore Idoneità per principianti 92/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
area/geometry good first issue help wanted kind/doc-mismatch severity/4-minor
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
Apich-Organization/rssn#295 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
-
chore claimed
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
schuyler/corvidae#1424 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno