-
Notifications
You must be signed in to change notification settings - Fork 2.6k
More robust process killing #3136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "roo-cline": patch | ||
| --- | ||
|
|
||
| More robust process killing |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,14 @@ | ||
| import { execa, ExecaError } from "execa" | ||
| import psTree from "ps-tree" | ||
| import process from "process" | ||
|
|
||
| import type { RooTerminal } from "./types" | ||
| import { BaseTerminalProcess } from "./BaseTerminalProcess" | ||
|
|
||
| export class ExecaTerminalProcess extends BaseTerminalProcess { | ||
| private terminalRef: WeakRef<RooTerminal> | ||
| private controller?: AbortController | ||
| private aborted = false | ||
| private pid?: number | ||
|
|
||
| constructor(terminal: RooTerminal) { | ||
| super() | ||
|
|
@@ -30,18 +32,17 @@ export class ExecaTerminalProcess extends BaseTerminalProcess { | |
|
|
||
| public override async run(command: string) { | ||
| this.command = command | ||
| this.controller = new AbortController() | ||
|
|
||
| try { | ||
| this.isHot = true | ||
|
|
||
| const subprocess = execa({ | ||
| shell: true, | ||
| cwd: this.terminal.getCurrentWorkingDirectory(), | ||
| cancelSignal: this.controller.signal, | ||
| all: true, | ||
| })`${command}` | ||
|
|
||
| this.pid = subprocess.pid | ||
| const stream = subprocess.iterable({ from: "all", preserveNewlines: true }) | ||
| this.terminal.setActiveStream(stream, subprocess.pid) | ||
|
|
||
|
|
@@ -116,7 +117,37 @@ export class ExecaTerminalProcess extends BaseTerminalProcess { | |
|
|
||
| public override abort() { | ||
| this.aborted = true | ||
| this.controller?.abort() | ||
|
|
||
| if (this.pid) { | ||
| psTree(this.pid, async (err, children) => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider wrapping the This comment was generated because it violated a code review rule: mrule_OR1S8PRRHcvbdFib. |
||
| if (!err) { | ||
| const pids = children.map((p) => parseInt(p.PID)) | ||
|
|
||
| for (const pid of pids) { | ||
| try { | ||
| process.kill(pid, "SIGINT") | ||
| } catch (e) { | ||
| console.warn( | ||
| `[ExecaTerminalProcess] Failed to send SIGINT to child PID ${pid}: ${e instanceof Error ? e.message : String(e)}`, | ||
| ) | ||
| // Optionally try SIGTERM or SIGKILL on failure, depending on desired behavior. | ||
| } | ||
| } | ||
| } else { | ||
| console.error( | ||
| `[ExecaTerminalProcess] Failed to get process tree for PID ${this.pid}: ${err.message}`, | ||
| ) | ||
| } | ||
| }) | ||
|
|
||
| try { | ||
| process.kill(this.pid, "SIGINT") | ||
| } catch (e) { | ||
| console.warn( | ||
| `[ExecaTerminalProcess] Failed to send SIGINT to main PID ${this.pid}: ${e instanceof Error ? e.message : String(e)}`, | ||
| ) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public override hasUnretrievedOutput() { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider replacing
console.logwith a structured logging solution (or using an existing logger) to adhere to our structured logging standards.This comment was generated because it violated a code review rule: mrule_OR1S8PRRHcvbdFib.