| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
|
The following comment was made by an LLM, it may be inaccurate: Based on my search, here are the related PRs that might be duplicates or closely related: Potentially Related PRs
Note: PR #12718 (the current PR) appears to be a comprehensive solution addressing the same orphaned process issue that previous PRs have attempted to fix. Check if #11603 and #7424 are closed/merged and whether this PR supersedes them or if there's overlapping work. |
Sorry, something went wrong.
|
yeah I was just hit with this issue as well. You have 68 opencode processes running, most dating back to Jan 28 - Feb 1. This happens when you close terminal windows without explicitly exiting opencode (Ctrl+C or /exit) - the processes keep running in the background.
Kill all opencode processes except the current one (PID 76275)ps aux | grep opencode | grep -v grep | grep -v 76275 | awk '{print $2}' | xargs kill |
Sorry, something went wrong.
|
Hmm I think that calling process.exit() explicitly skips some shutdown procedures which probably can cause corrupted writes (stdout/files etc) Additionally it skips finally() blocks and other background work since it stops the event loop and exits synchronously. Here is the Node docs which transfer to Bun as well: https://nodejs.org/api/process.html#processexitcode |
Sorry, something went wrong.
|
@goniz Thanks for the feedback! You're right — I've updated the signal handlers to avoid calling process.exit() directly. They now remove their own listener and re-raise the signal so the default OS handler runs, allowing finally blocks and pending I/O to complete normally. The only place process.exit() remains is in the index.ts safety net, which fires after a 3s timeout as a last resort if graceful shutdown hangs. |
Sorry, something went wrong.
| for (const signal of ["SIGHUP", "SIGTERM"] as const) { | ||
| const handler = () => { | ||
| process.off(signal, handler) | ||
| process.kill(process.pid, signal) | ||
| } | ||
| process.on(signal, handler) | ||
| } |
There was a problem hiding this comment.
Check if you can use the process.once() instead of doing this dance.
If not, extract to a utility function and document the pattern
Sorry, something went wrong.
There was a problem hiding this comment.
Good cal. switched all signal handlers to process.once() across the codebase (serve.ts, attach.ts, thread.ts, worker.ts, index.ts). No more manual off dance.
Sorry, something went wrong.
| if (ppid > 1) { | ||
| const monitor = setInterval(() => { | ||
| try { | ||
| process.kill(ppid, 0) |
There was a problem hiding this comment.
I think that this can lie due to race conditions. What if the parent dies and his pid gets recycled?
You can try checking if the processed moved to live under init as ppid / p group? Check me
Sorry, something went wrong.
There was a problem hiding this comment.
You're right. the stale PID + kill(pid, 0) approach is vulnerable to PID recycling. Replaced it with a live process.ppid check each interval: when the worker gets reparented to init (ppid === 1), we know the parent is gone. Also gated behind process.platform !== "win32" since ppid semantics don't apply there.
Sorry, something went wrong.
Tier 1 bug fixes: - Fix O(n²) bash output concatenation with StreamingOutput class (anomalyco#9693) - Fix memory leaks in Bus.once, Format, Plugin, ShareNext, Bootstrap (anomalyco#13514) - Fix FileTime race condition using actual file mtime instead of JS clock - Free memory on compaction prune: clear output/attachments/metadata (anomalyco#7049) - Throttle reasoning-delta storage writes to 50ms intervals (anomalyco#11328) - Handle SIGHUP/SIGTERM to prevent orphaned processes (anomalyco#12718) - Add process.once("close") handler for bash tool reliability Tier 2 features: - Support 1M context window for Anthropic models via beta header (anomalyco#14375) - Input-only token counting for compaction with limit.input models - MCP lazy loading: on-demand tool discovery via mcp_search tool (anomalyco#8771) - MCP servers listed in system prompt when lazy mode enabled - StreamingOutput: output_filter regex for build diagnostics - LSP server cleanup callback for temp directory removal - Extract formatSize utility from uninstall to shared util/format - GitHub CI: fix Bus subscription leak in session event handler Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Closing this pull request because it has had no updates for more than 60 days. If you plan to continue working on it, feel free to reopen or open a new PR. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
What does this PR do?
Fixes #10563, relates to #11225, #11527
When a terminal tab/window is closed, the OS sends SIGHUP to the process group. OpenCode has no SIGHUP handler, so the process ignores it and stays alive as an orphan under launchd (PPID=1), consuming memory indefinitely.
This adds SIGHUP and SIGTERM handlers to all long-running entry points:
The layered approach works like this: command-specific handlers do graceful cleanup and exit immediately, while the index.ts safety net force-exits after 3s if a command-specific handler hangs.
How did you verify your code works?