[Bug] PL/Python statement_timeout can leave a zombie subprocess despite finally: wait()
Los mantenedores suelen responder en 2 días
Evaluación
Este issue todavía no se ha evaluado.
Descripción
Apache Cloudberry version
main, probably REL_2_STABLE
What happened
When statement_timeout cancels a PL/Python function waiting in subprocess.Popen.communicate(), the SQL statement can return a cancellation error while its timeout child remains a zombie, despite an explicit process.wait() in a finally block.
The zombie remains a child of the backend after subsequent SQL statements and disappears when the backend session closes. The monitored command itself has already finished.
This was discovered while reviewing #2117, but also reproduces with a harmless sleep command and does not require diskquota or segment recovery.
What you think should happen instead
The exited subprocess should be reaped before the cancellation error is returned to the client.
How to reproduce
The measured runs used coordinator connections with options='-c gp_role=utility' and autocommit enabled.
To reproduce under the same conditions, start an interactive psql session connected to the coordinator. Replace the placeholders with your connection details:
PGOPTIONS='-c gp_role=utility' psql -h <coordinator_host> -p <coordinator_port> -d <database>
Run the following statements with autocommit enabled and without an explicit transaction. Record the value returned by SELECT pg_backend_pid();.
CREATE EXTENSION IF NOT EXISTS plpython3u;
CREATE OR REPLACE FUNCTION public.zombie_repro()
RETURNS void LANGUAGE plpython3u AS $$
import subprocess
p = subprocess.Popen(
['timeout', '-k', '1', '5', 'sleep', '0.3'],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT
)
try:
p.communicate()
finally:
p.wait()
$$;
SELECT pg_backend_pid();
SET statement_timeout = '100ms';
SELECT public.zombie_repro();
RESET statement_timeout;
SELECT 1;
Keep the psql session open after the timeout error. From another terminal on the coordinator host, inspect the backend’s child processes, replacing <backend_pid> with the recorded PID:
ps -o pid,ppid,stat,comm --ppid <backend_pid>
When the issue reproduces, a timeout process appears with STAT containing Z and PPID matching the backend PID. It persists after subsequent SQL statements and disappears when the session closes.
The result is timing-dependent and does not occur on every invocation. If necessary, repeat the procedure using a fresh connection for each attempt.
Observed reproduction rates:
- Minimal example above: 16 out of 20 independent backend sessions.
- Exact
pg_recoverseghelper from #2117, invoking realgprecoverseg: 12 out of 20 independent backend sessions.
Every attempt returned SQLSTATE 57014 from the function call. Zombie detection was performed after RESET statement_timeout, a 200 ms delay, and SELECT 1. A separate check confirmed persistence after two seconds and another SELECT 1.
Each attempt closed its connection afterwards, so the counts do not include children left by previous attempts.
Operating System
Any
Anything else
The results above were verified in this environment:
- Ubuntu 22.04, Linux x86_64.
- Python 3.10.12.
- Cloudberry 3.0.0-devel / PostgreSQL 16.9, with assertions enabled.
- Server source commit:
070d9d33b3bacea45d991f54c100b4bc077c8d58.
Possible cause to investigate: StatementTimeoutHandler signals both the backend process group and the backend PID, while PLy_handle_cancel_interrupt queues KeyboardInterrupt through Py_AddPendingCall. Repeated cancellation may interrupt cleanup. This is a hypothesis, not a confirmed root cause.
Are you willing to submit PR?
- Yes, I am willing to submit a PR!
Code of Conduct
- I agree to follow this project's Code of Conduct.
- Lenguaje dominante
- C
- Estrellas
- 1.4k
- Forks
- 265
- Merge medio
- 3 d 17 h
- PR fusionados (30 d)
- 68
Preparar el entorno
- Sin Dockerfile ni 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 apache/cloudberry
-
[Bug] Expand fails to recognize user-defined tablespacesPosiblemente ocupada @nix-oss la tomó hace 72 días. Abiertotype: Bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
apache/cloudberry#1885 · 2 reacciones ·
Los mantenedores suelen responder en 2 días
-
gpexpand first stage fails: 'SyncPackages' object has no attribute 'ret' (extension sync never runs; regression)Posiblemente ocupada @talmacschen-arch la tomó hace 134 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 86/100
apache/cloudberry#1825 ·
Los mantenedores suelen responder en 2 días
-
[Bug] GPORCA: “could not find MotionState” for correlated EXISTS with LIMIT and a scalar subqueryPosiblemente ocupada @Alena0704 la tomó hace 1 día. Abiertotype: Bug
apache/cloudberry#2221 · 1 asignado ·
Los mantenedores suelen responder en 2 días
-
Dificultad 4/5 3-5 días Aptitud para principiantes 42/100
apache/cloudberry#2214 · 1 comentario ·
Los mantenedores suelen responder en 2 días
-
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
apache/cloudberry#2213 · 4 comentarios ·
Los mantenedores suelen responder en 2 días
Todos los issues de apache/cloudberry
Issues similares
-
vim.filetype.match() prefixes a URL buffer name with the cwd before passing it to filetype functionsAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 73/100
Los mantenedores suelen responder en 1 día
-
stream_curl: retry_count never resets after a successful reconnect, so long sequential streams die after 5 dropsPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
mpv-player/mpv#18728 ·
Los mantenedores suelen responder en 1 día
-
followup Prio 📌
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
cyrusimap/cyrus-imapd#6640 ·
Los mantenedores suelen responder en 2 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 60/100
Los mantenedores suelen responder en 1 día