GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — fix(cli): handle SIGHUP to prevent orphaned processes on terminal close by shjeong92 · Pull Request #12718 · anomalyco/opencode ConversationWhat 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?
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
shjeong92
force-pushed
the
fix/handle-sighup-prevent-orphaned-processes
branch
from
4591da7 to
ecdb049
Compare
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
This was referenced
|
There was an error while loading. Please reload this page.
|
Hmm I think that calling Additionally it skips Here is the Node docs which transfer to Bun as well: https://nodejs.org/api/process.html#processexitcode |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@goniz Thanks for the feedback! You're right — I've updated the signal handlers to avoid calling The only place |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
df894ca to
f07b5c9
Compare
| 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.
The reason will be displayed to describe this comment to others. Learn more.
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 an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
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.
There was an error while loading. Please reload this page.
| if (ppid > 1) { | ||
| const monitor = setInterval(() => { | ||
| try { | ||
| process.kill(ppid, 0) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
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 an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
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.
There was an error while loading. Please reload this page.
7b5e903 to
ebeb3df
Compare
ebeb3df to
c8d3c2e
Compare
c8d3c2e to
eaf161c
Compare
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 <[email protected]>
|
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.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
Memory Leak: Orphaned processes when terminal closes without explicit exit
There was an error while loading. Please reload this page.