Skip to content

Comments

fix: handle SIGHUP/SIGTERM/SIGPIPE to prevent orphaned processes#14548

Open
kevinWangSheng wants to merge 1 commit intoanomalyco:devfrom
kevinWangSheng:fix/sighup-handler-orphaned-processes
Open

fix: handle SIGHUP/SIGTERM/SIGPIPE to prevent orphaned processes#14548
kevinWangSheng wants to merge 1 commit intoanomalyco:devfrom
kevinWangSheng:fix/sighup-handler-orphaned-processes

Conversation

@kevinWangSheng
Copy link

@kevinWangSheng kevinWangSheng commented Feb 21, 2026

Issue for this PR

Closes #14504

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Adds signal handlers for SIGHUP, SIGTERM, and SIGPIPE that call process.exit(1). Without these, when a terminal dies (SSH disconnect, tmux pane close), opencode processes become orphaned because cli.parse() never resolves and process.exit() in the finally block never runs. Each orphan leaks ~4.7 GB of RAM.

How did you verify your code works?

Reviewed the 3-line change. process.on(sig, () => process.exit(1)) triggers the existing finally-block cleanup. All CI checks pass.

Screenshots / recordings

N/A - no UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

When a controlling terminal is destroyed (SSH disconnect, tmux pane
close), opencode processes become orphaned and continue running
indefinitely because no signal handler triggers process.exit(). Add
handlers for SIGHUP, SIGTERM, and SIGPIPE so the existing subprocess
cleanup in the finally block runs promptly.

Fixes anomalyco#14504

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions github-actions bot added the needs:compliance This means the issue will auto-close after 2 hours. label Feb 21, 2026
@github-actions
Copy link
Contributor

The following comment was made by an LLM, it may be inaccurate:

Potential Duplicate PRs Found

Several related PRs exist that address similar orphaned process issues:

  1. PR fix(tui): add signal handlers to prevent orphaned processes on terminal close #13848 - fix(tui): add signal handlers to prevent orphaned processes on terminal close - Directly related, handles signal handlers for the same issue

  2. PR fix: resolve memory leaks and zombie processes from missing cleanup handlers #13186 - fix: resolve memory leaks and zombie processes from missing cleanup handlers - Addresses cleanup handler issues that prevent zombie processes

  3. PR fix: add signal handlers to prevent orphaned processes #12877 - fix: add signal handlers to prevent orphaned processes - Similar signal handler approach

  4. PR fix(cli): handle SIGHUP to prevent orphaned processes on terminal close #12718 - fix(cli): handle SIGHUP to prevent orphaned processes on terminal close - Specifically handles SIGHUP for terminal close scenarios

  5. PR fix(tui): graceful exit on Ctrl+C and resolve multiline paste corruption #14440 - fix(tui): graceful exit on Ctrl+C and resolve multiline paste corruption - Related to signal handling and graceful exit

Recommendation: Check if any of these existing PRs (especially #13848, #13186, or #12877) already implement similar signal handler logic. PR #14548 may be duplicating work if these weren't merged or completely address the same issue.

@github-actions github-actions bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Feb 21, 2026
@github-actions
Copy link
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Missing SIGHUP handler causes orphaned processes to leak ~4.7 GB each after terminal death

1 participant