Remote schema download has no timeout, so a stalled connection hangs the run indefinitely
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Anfängerfreundlichkeit
- 77/100
- Issue-Typ
- Bug
- Klarheit
- Klar beschrieben
- Aktivitätsstatus
- Aktiv
- Tech-Stack
- python
- Bereich
- cli, networking
Rechercherichtung
Beginne in src/check_jsonschema/cachedownloader.py bei _get_request und verfolge, wie die vorhandene Wiederholungsschleife requests.RequestException behandelt. Füge für die Anfrage eine begrenzte Verbindungs- und Lesezeitüberschreitung hinzu und prüfe anschließend die Tests für Remote-Schema-Downloads und Wiederholungsfehler. Fertig ist es, wenn eine stockende Anfrage die Wiederholungs- und Fehlerbehandlung erreicht, statt unbegrenzt zu hängen.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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.
- Vorherrschende Sprache
- Python
- Sterne
- 357
- Forks
- 74
- Ø Merge
- 8 T. 14 Std.
- Gemergte PRs (30 T.)
- 3
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Keine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus python-jsonschema/check-jsonschema
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 77/100
python-jsonschema/check-jsonschema#737 · 2 Kommentare ·
-
New vendored schemas: DatadogEvtl. vergeben @lannuttia hat das vor 120 Tagen übernommen. Offen
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 35/100
-
Feature Request: Support URL rewriteEvtl. wieder frei Ein Pull Request dazu wurde ohne Merge geschlossen. Offen
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 48/100
-
Support ETag for cache validation when Last-Modified is unavailableEvtl. vergeben @sirosen hat das vor 253 Tagen übernommen. Offenenhancement
python-jsonschema/check-jsonschema#668 · 9 Kommentare · 1 zugewiesene Person ·
-
Vendor multitool schemaEvtl. wieder frei Ein Pull Request dazu wurde ohne Merge geschlossen. Offen
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 55/100
Alle Issues in python-jsonschema/check-jsonschema
Ähnliche Issues
-
area:print-dispatch
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 92/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Maintainer antworten meist innerhalb von 1 Tag
-
area/geometry good first issue help wanted kind/doc-mismatch severity/4-minor
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
Apich-Organization/rssn#295 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
-
chore claimed
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
schuyler/corvidae#1424 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag