-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Memory leak: process.stdin event listeners never removed in ACP command #11696
Copy link
Copy link
Open
Labels
perfIndicates a performance issue or need for optimizationIndicates a performance issue or need for optimization
Description
Summary
The ACP (Agent Communication Protocol) command adds event listeners to process.stdin that are never removed, causing a memory leak in long-running processes.
Location
packages/opencode/src/cli/cmd/acp.ts:47-67
Issue
The code adds multiple listeners to process.stdin but never removes them:
// First set of listeners at lines 47-51
process.stdin.on("data", (chunk: Buffer) => {
controller.enqueue(new Uint8Array(chunk))
})
process.stdin.on("end", () => controller.close())
process.stdin.on("error", (err) => controller.error(err))
// ... later, DUPLICATE listeners are added at lines 64-66
await new Promise((resolve, reject) => {
process.stdin.on("end", resolve) // Duplicate!
process.stdin.on("error", reject) // Duplicate!
})Impact
- Severity: Medium
- Type: Memory Leak
- Affected: Long-running ACP processes
Suggested Fix
Use once() for listeners that should only fire once:
await new Promise((resolve, reject) => {
process.stdin.once("end", resolve)
process.stdin.once("error", reject)
})Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
perfIndicates a performance issue or need for optimizationIndicates a performance issue or need for optimization