Remote schema download has no timeout, so a stalled connection hangs the run indefinitely
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 2/5
- Tempo estimado
- 1-3 horas
- Facilidade para iniciantes
- 77/100
- Tipo de issue
- Bug
- Clareza
- Claramente especificada
- Status de atividade
- Ativa
- Stack de tecnologia
- python
- Domínio
- cli, networking
Direção de pesquisa
Comece em src/check_jsonschema/cachedownloader.py, em _get_request, e acompanhe como o loop de repetição existente trata requests.RequestException. Adicione à requisição um tempo limite definido para conexão e leitura e, em seguida, confira os testes que cobrem downloads de esquemas remotos e falhas nas tentativas. O trabalho está concluído quando uma requisição travada chega ao tratamento de repetição e falha, em vez de ficar bloqueada indefinidamente.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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.
- Linguagem predominante
- Python
- Estrelas
- 357
- Forks
- 74
- Merge médio
- 8d 14h
- PRs com merge (30d)
- 3
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Sem modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de python-jsonschema/check-jsonschema
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 77/100
python-jsonschema/check-jsonschema#737 · 2 comentários ·
-
New vendored schemas: DatadogTalvez já em andamento @lannuttia assumiu há 120 dias. Aberta
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 35/100
-
Feature Request: Support URL rewriteTalvez livre de novo Um pull request para esta issue foi fechado sem ser mesclado. Aberta
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 48/100
-
Support ETag for cache validation when Last-Modified is unavailableTalvez já em andamento @sirosen assumiu há 253 dias. Abertaenhancement
python-jsonschema/check-jsonschema#668 · 9 comentários · 1 responsável ·
-
Vendor multitool schemaTalvez livre de novo Um pull request para esta issue foi fechado sem ser mesclado. Aberta
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 55/100
Todas as issues de python-jsonschema/check-jsonschema
Issues semelhantes
-
area:print-dispatch
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 92/100
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
Mantenedores costumam responder em até 1 dia
-
area/geometry good first issue help wanted kind/doc-mismatch severity/4-minor
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
Apich-Organization/rssn#295 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 88/100
-
chore claimed
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
schuyler/corvidae#1424 · 2 comentários ·
Mantenedores costumam responder em até 1 dia