Bug: Reaper is force-removed at interpreter exit since 4.15.0, session containers are never reaped
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 72/100
Línea de trabajo
Read the atexit registration for Reaper.delete_instance and the Reaper._container.stop() path in src/testcontainers/core/container.py, then inspect the regression tests around reaper cleanup. Reproduce with the issue's short Python command and check Docker events or the session label after waiting 15 seconds. Done when normal interpreter exit closes the socket, leaves Ryuk running long enough to reap the session containers, and the regression test passes.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Describe the bug
Since 4.15.0, containers started by a process are left running after that process exits normally. Ryuk never reaps them.
#1017 registered Reaper.delete_instance with atexit to close the Ryuk socket before interpreter shutdown. delete_instance() also calls Reaper._container.stop(), which is remove(force=True), so the Ryuk container gets SIGKILL at the same moment the socket closes:
Ryuk only reaps a session RYUK_RECONNECTION_TIMEOUT (10s by default) after the last connection drops. Killed at exit, it never gets there. Every container of a session that ends normally without stopping its containers itself stays behind. This is the common case Ryuk exists for, e.g. a session-scoped pytest fixture that relies on Ryuk for cleanup.
docker events for the Ryuk container at interpreter exit:
start <ryuk id>
kill <ryuk id> sig=9
destroy <ryuk id>
On 4.14.2 the same script leaves nothing behind. With the process ending through os._exit(0), which skips atexit, 4.15.0 works too, and the Ryuk log shows the normal path:
Client disconnected: 172.17.0.1:49870
Timeout waiting for connection
Removed 1 container(s), 0 network(s), 0 volume(s) 0 image(s)
Expected: the process exits, Ryuk removes the session's containers about 10s later.
Actual: Ryuk is force-removed at exit, the session's containers keep running.
To Reproduce
python -c "
from testcontainers.core.container import DockerContainer
c = DockerContainer('alpine:3.20').with_command('sleep infinity').start()
print(c.get_wrapped_container().short_id)
"
sleep 15
docker ps --filter label=org.testcontainers.lang=python
# 4.14.2: empty. 4.15.0 and main: the alpine container is still Up.
Workarounds: pin testcontainers<4.15, or drop the handler after the reaper is created with atexit.unregister(Reaper.delete_instance).
Closing only the socket at exit keeps the fix from #1017 (no ResourceWarning) and lets Ryuk do its job. #1125 hits a 409 from this same atexit call when Ryuk is already being removed. Fixing this means the atexit path no longer runs into it. I'll open a PR with a fix and a regression test.
Runtime environment
- testcontainers 4.15.0, reproduced on
mainat 6146aa1 - Python 3.12.12
- macOS with Colima (Ubuntu 24.04.4 VM, Docker Engine 29.2.1)
- Lenguaje dominante
- Python
- Estrellas
- 2.3k
- Forks
- 395
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Incluye un Dockerfile o un archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de testcontainers/testcontainers-python
-
Bug: HttpWaitStrategy ignores response predicates for accepted HTTP error statusesPosiblemente ocupada @PranavMulakala la tomó hace 24 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
testcontainers/testcontainers-python#1143 ·
Los mantenedores suelen responder en 1 día
-
Bug: LogMessageWaitStrategy: a container that exits before its message raises without its logs, and __enter__ then removes the containerPosiblemente ocupada @granzer69 la tomó hace 25 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
testcontainers/testcontainers-python#1138 ·
Los mantenedores suelen responder en 1 día
-
Updating the documentationAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 67/100
testcontainers/testcontainers-python#1086 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Bug: [minio] _healthcheck calls for nested wait_container_is_ready resulting in long wait timeAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
testcontainers/testcontainers-python#578 · 5 comentarios ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 35/100
testcontainers/testcontainers-python#1137 ·
Los mantenedores suelen responder en 1 día
Todos los issues de testcontainers/testcontainers-python
Issues similares
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 77/100
canonical/paas-charm#407 · 1 comentario ·
Los mantenedores suelen responder en 5 días
-
bug
Dificultad 1/5 Menos de una hora Aptitud para principiantes 90/100
FAIRmat-NFDI/pynxtools-spm#136 ·
Los mantenedores suelen responder en 1 día
-
enhancement tooling
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
Los mantenedores suelen responder en 1 día
-
`read_nexus` entry point points to a function that no longer existsPosiblemente ocupada @RubelMozumder la tomó hoy. Abiertoannotator bug
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
FAIRmat-NFDI/pynxtools#876 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
[Bug]: HTTP 499 (Client Closed Request) is classified as a non-retryable format_error, so a mid-flight abort fails the turn over instead of retryingPosiblemente ocupada @yipinghuang1991 la tomó hoy. Abiertocomp/agent P2 type/bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
NousResearch/hermes-agent#156837 ·
Los mantenedores suelen responder en 1 día