Bug: HttpWaitStrategy ignores response predicates for accepted HTTP error statuses
Mantenedores costumam responder em até 1 dia
Avaliação
- Dificuldade
- 2/5
- Tempo estimado
- 1-3 horas
- Facilidade para iniciantes
- 85/100
Direção de pesquisa
Comece em testcontainers/core/wait_strategies.py em HttpWaitStrategy._handle_http_error(), que retorna True sem verificar _response_predicate. Leia _check_response() para ver a avaliação normal do predicado. Execute o script de reprodução da issue para ver o ready falso e depois edite o ramo de erro para avaliar o predicado. Concluído significa que o script gera TimeoutError.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
Describe the bug
HttpWaitStrategy.for_response_predicate() is not evaluated when an HTTP endpoint returns an explicitly accepted error status, such as 404 or 503. The strategy reports ready even when the response body does not match the predicate.
This affects both for_status_code(...) and for_status_code_matching(...). HTTP 200 responses do evaluate the body predicate. A caller that deliberately accepts an error status still needs the additional body condition to pass; accepting the status should not bypass that condition.
Found while testing HTTP readiness behavior on main at 6146aa1170f415fcc825ed9bddc4eacbeb937a12 (package version 4.15.0). I searched issues and PRs for HttpWaitStrategy, for_response_predicate, response predicate, and HTTPError and did not find this behavior reported. The HTTPError resource-cleanup work in #1115 is related code but a different problem.
Reproduction
This endpoint always returns 503 with body starting. The status is deliberately accepted, but the body predicate requires ready.
"""Reproduce a false-positive HTTP readiness result (requires Docker)."""
from testcontainers.core.container import DockerContainer
from testcontainers.core.wait_strategies import HttpWaitStrategy
server = """
from http.server import BaseHTTPRequestHandler, HTTPServer
class Handler(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(503)
self.end_headers()
self.wfile.write(b"starting")
HTTPServer(("0.0.0.0", 8080), Handler).serve_forever()
"""
strategy = (
HttpWaitStrategy(8080)
.for_status_code(503)
.for_response_predicate(lambda body: body == "ready")
.with_startup_timeout(2)
.with_poll_interval(0.1)
)
try:
with (
DockerContainer("python:3.12-alpine")
.with_exposed_ports(8080)
.with_command(["python", "-u", "-c", server])
.waiting_for(strategy)
):
raise AssertionError("BUG: marked ready even though the body is always 'starting'")
except TimeoutError:
print("Correct: the body never matched, so readiness timed out.")
Expected behavior
The wait should continue polling and raise TimeoutError because the body never matches.
Actual behavior
The context manager enters immediately after the first HTTP response; the assertion fails. In a second reproduction, an endpoint returning starting on request 1 and ready on request 2 receives only one request before the wait finishes.
Root cause and proposed fix
urlopen() raises HTTPError for error statuses. _handle_http_error() accepts the status and returns True without evaluating _response_predicate. The normal response path in _check_response() does evaluate it.
Evaluate the body predicate for accepted HTTP errors while the existing with e: block still owns the response. This preserves status-only waits and response cleanup.
Runtime environment
- macOS / Apple silicon; Colima Docker runtime
- Regression tests reproduced on Python 3.12.14
- Patch validated on Python 3.10.22, 3.12.14, 3.13.17, and 3.14.9
- Real HTTP server in
python:3.12-alpine
- Linguagem predominante
- Python
- Estrelas
- 2.3k
- Forks
- 395
- Métricas de merge de PRs
- Nenhum PR com merge em 30d
Preparar o ambiente
Inicia o contêiner de desenvolvimento do projeto no navegador, com a sua própria conta do GitHub.
- Inclui um Dockerfile ou arquivo Docker Compose
- Tem um 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 testcontainers/testcontainers-python
-
Bug: LogMessageWaitStrategy: a container that exits before its message raises without its logs, and __enter__ then removes the containerTalvez já em andamento @granzer69 assumiu há 25 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
testcontainers/testcontainers-python#1138 ·
Mantenedores costumam responder em até 1 dia
-
Updating the documentationAberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 67/100
testcontainers/testcontainers-python#1086 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
Bug: [minio] _healthcheck calls for nested wait_container_is_ready resulting in long wait timeAberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
testcontainers/testcontainers-python#578 · 5 comentários ·
Mantenedores costumam responder em até 1 dia
-
Bug: Reaper is force-removed at interpreter exit since 4.15.0, session containers are never reapedTalvez já em andamento @pantafive assumiu há 25 dias. Aberta
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 72/100
testcontainers/testcontainers-python#1140 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 35/100
testcontainers/testcontainers-python#1137 ·
Mantenedores costumam responder em até 1 dia
Todas as issues de testcontainers/testcontainers-python
Issues semelhantes
-
area: ci bug good first issue help wanted
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 84/100
hffgzktbcc-blip/ounce-core#484 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 66/100
ranxianglei/billion-context#7063 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 65/100
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
-
needs-triage
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 84/100
MakazhanAlpamys/Soup#2971 ·
Mantenedores costumam responder em até 1 dia