[PR #48] [CLOSED] fix: reap zombie processes via tini PID 1 and os.killpg() for process groups #115

Closed
opened 2026-10-18 21:10:56 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-terminal/pull/48
Author: @kb5000
Created: 3/11/2026
Status: ❌ Closed

Base: main ← Head: main


📝 Commits (1)

  • d7787ce fix: reap zombie processes via tini PID 1 and os.killpg() for process groups

📊 Changes

3 files changed (+16 additions, -8 deletions)

View changed files

📝 Dockerfile (+2 -2)
📝 open_terminal/main.py (+9 -2)
📝 open_terminal/utils/runner.py (+5 -4)

📄 Description

Problem

When running in Docker, two related zombie/orphan process issues exist:

  1. No init process: entrypoint.sh uses exec open-terminal "$@", which
    makes the Python/uvicorn process run directly as PID 1. Python has no
    SIGCHLD handler to reap orphaned grandchildren (e.g. processes spawned
    inside a terminal session that then loses its parent). These accumulate as
    zombie processes indefinitely.

  2. Incomplete process group cleanup: _cleanup_session and
    PtyRunner.kill() sent signals only to the direct shell PID, not to the
    entire process group. Background processes started inside a terminal session
    (e.g. sleep 100 &) were left running as orphans. Additionally,
    _cleanup_session called process.kill() but never called process.wait()
    afterwards, so the kernel kept the PCB in zombie state Z.

Fix

Dockerfile — add tini as PID 1:

sudo tmux screen tini \
...
ENTRYPOINT ["/usr/bin/tini", "--", "/app/entrypoint.sh"]

Testing

Built the Docker image and verified with a smoke test:

  • tini is PID 1 ✓
  • DELETE /execute/{id} kills all child processes in the group, no zombies ✓
  • DELETE /api/terminals/{id} cleans up the shell session completely ✓
  • WebSocket disconnect triggers full session cleanup, background jobs killed ✓

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/open-webui/open-terminal/pull/48 **Author:** [@kb5000](https://github.com/kb5000) **Created:** 3/11/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `main` --- ### 📝 Commits (1) - [`d7787ce`](https://github.com/open-webui/open-terminal/commit/d7787cec578b6a5605ac962a2e0a71a38838d92b) fix: reap zombie processes via tini PID 1 and os.killpg() for process groups ### 📊 Changes **3 files changed** (+16 additions, -8 deletions) <details> <summary>View changed files</summary> 📝 `Dockerfile` (+2 -2) 📝 `open_terminal/main.py` (+9 -2) 📝 `open_terminal/utils/runner.py` (+5 -4) </details> ### 📄 Description ## Problem When running in Docker, two related zombie/orphan process issues exist: 1. **No init process**: `entrypoint.sh` uses `exec open-terminal "$@"`, which makes the Python/uvicorn process run directly as PID 1. Python has no `SIGCHLD` handler to reap orphaned grandchildren (e.g. processes spawned inside a terminal session that then loses its parent). These accumulate as zombie processes indefinitely. 2. **Incomplete process group cleanup**: `_cleanup_session` and `PtyRunner.kill()` sent signals only to the direct shell PID, not to the entire process group. Background processes started inside a terminal session (e.g. `sleep 100 &`) were left running as orphans. Additionally, `_cleanup_session` called `process.kill()` but never called `process.wait()` afterwards, so the kernel kept the PCB in zombie state `Z`. ## Fix **`Dockerfile`** — add `tini` as PID 1: ```dockerfile sudo tmux screen tini \ ... ENTRYPOINT ["/usr/bin/tini", "--", "/app/entrypoint.sh"] ``` ## Testing Built the Docker image and verified with a smoke test: - tini is PID 1 ✓ - DELETE /execute/{id} kills all child processes in the group, no zombies ✓ - DELETE /api/terminals/{id} cleans up the shell session completely ✓ - WebSocket disconnect triggers full session cleanup, background jobs killed ✓ --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-18 21:10:56 +00:00
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
open-webui/open-terminal#115
No description provided.