GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: add SIGHUP/SIGTERM/SIGPIPE handlers to prevent orphaned processes by coleleavitt · Pull Request #14505 · anomalyco/opencode

Conversation

@coleleavitt

@coleleavitt coleleavitt commented Feb 20, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add signal handlers for SIGHUP, SIGTERM, and SIGPIPE in index.ts to call process.exit(1) on terminal death
  • Prevents orphaned opencode processes that leak ~4.7 GB RAM each when controlling terminal is destroyed

Problem

When a terminal dies (SSH disconnect, tmux pane close, terminal crash), the kernel sends SIGHUP to the process group. Without a handler, the Bun event loop continues running because:

  1. The TUI promise in thread.ts blocks on stdin that will never produce input
  2. cli.parse() in index.ts never resolves
  3. process.exit() in the finally block never executes
  4. Process runs indefinitely as an orphan (PPID=1)

On a system using oh-my-opencode with tmux, this accumulated 14 orphaned processes consuming ~66 GB of RAM total.

Fix

for (const sig of ["SIGHUP", "SIGTERM", "SIGPIPE"] as const) {
  process.on(sig, () => {
    process.exit(1)
  })
}

Placed after the existing unhandledRejection/uncaughtException handlers and before cli.parse().

Testing

  • Verified no LSP diagnostics/errors on the changed file
  • The fix is minimal and follows the same pattern as the existing process.exit() call in the finally block (line 202)

Fixes #14504

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@coleleavitt
fix: add SIGHUP/SIGTERM/SIGPIPE handlers to prevent orphaned processes
76ee4ab
When a controlling terminal is destroyed (SSH disconnect, tmux pane close),
opencode processes become orphaned because the TUI event loop blocks on
stdin that will never produce input, preventing process.exit() from executing.

Each orphaned instance leaks ~4.7 GB of RAM. On systems using tmux-based
session managers (e.g. oh-my-opencode), this can accumulate to 60+ GB.

Add signal handlers for SIGHUP, SIGTERM, and SIGPIPE that call process.exit(1)
immediately, ensuring clean shutdown on terminal death.

Fixes anomalyco#14504
@github-actions github-actions Bot added contributor needs:compliance This means the issue will auto-close after 2 hours. labels Feb 20, 2026
@github-actions

github-actions Bot commented Feb 20, 2026

Copy link
Copy Markdown
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions

github-actions Bot commented Feb 20, 2026

Copy link
Copy Markdown
Contributor

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

Based on the search results, I found several related PRs that address similar issues with orphaned processes and signal handling:

Potential Related/Duplicate PRs:

  1. PR fix(cli): handle SIGHUP to prevent orphaned processes on terminal close #12718 - fix(cli): handle SIGHUP to prevent orphaned processes on terminal close

    • Directly addresses the same SIGHUP signal handling issue for preventing orphaned processes on terminal close
  2. 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

    • Adds signal handlers to prevent orphaned processes, likely for the TUI component
  3. PR fix: add signal handlers to prevent orphaned processes #12877 - fix: add signal handlers to prevent orphaned processes

    • General signal handlers to prevent orphaned processes
  4. 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 memory leaks and zombie processes from missing cleanup handlers
  5. PR fix: prevent orphaned worker process when killed #11603 - fix: prevent orphaned worker process when killed

    • Addresses orphaned worker processes
  6. PR fix: force kill MCP server processes on dispose to prevent orphan processes #7424 - fix: force kill MCP server processes on dispose to prevent orphan processes

    • Targets MCP server orphaned processes specifically

Why they might be related: These PRs all tackle the same core problem of orphaned processes caused by signal handling, though some target specific components (CLI, TUI, MCP server) or attempt different approaches. PR #14505 (current) appears to be a comprehensive fix at the main index level that complements earlier attempts.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions

github-actions Bot commented Feb 21, 2026

Copy link
Copy Markdown
Contributor

This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.

Feel free to open a new pull request that follows our guidelines.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot closed this Feb 21, 2026
@coleleavitt
coleleavitt deleted the fix/sighup-orphaned-processes branch March 4, 2026 21:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

contributor needs:compliance This means the issue will auto-close after 2 hours.

Projects

None yet

Milestone

No milestone

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

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@coleleavitt
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.