Skip to content

fix: multiple memory leaks in long-running sessions #10913

Closed

Description

@sgInnora

Bug Description

Several memory leaks occur during long-running opencode sessions, causing RSS to grow continuously:

  1. AsyncQueue never terminates (util/queue.ts) - [Symbol.asyncIterator] loops forever with no close mechanism, preventing GC of consumers.

  2. Bash tool unbounded string concatenation (tool/bash.ts:167-189) - stdout/stderr appended via output += chunk.toString() with no size limit. Commands producing large output (e.g., find /) cause unbounded memory growth.

  3. LSP diagnostics Map never cleared (lsp/client.ts:51) - diagnostics Map accumulates entries indefinitely. shutdown() disposes the connection but doesn't clear the map.

  4. Bus subscriptions Map not cleared on dispose (bus/index.ts) - Instance dispose callback fires wildcard subscribers but never calls subscriptions.clear().

  5. PTY buffer string concatenation (pty/index.ts:136-150) - session.buffer += data then session.buffer.slice(-BUFFER_LIMIT) causes repeated large string allocation and GC pressure.

  6. Instance.disposeAll() not called on process exit (index.ts) - The main finally block calls process.exit() without disposing instances, leaking subprocess handles.

Reproduction

  1. Start opencode, run a command producing large output (find / -name "*.ts")
  2. Monitor with top -pid <PID> - RSS grows without bound
  3. Idle for 10+ minutes - memory does not decrease

Environment

  • opencode v1.1.36
  • macOS Darwin 24.6.0
  • Bun 1.3.5

Activity

  1. added
    perfIndicates a performance issue or need for optimization
    on Jan 27, 2026
  2. github-actions commented on Jan 27, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    Feel free to ignore if none of these address your specific case.

  3. KaranjotVendal commented on Feb 3, 2026

    @KaranjotVendal

    I believe I have encountered the same issue. Seems like the following PR #11717 and PR #10914 seems to be fixing the solution.

    Image

  4. cdenneen commented on Feb 18, 2026

    @cdenneen

    Looks like people haven't gotten a fix working for all the memory issues. Anyone see improvement with this? My opencode serve is killing my server multiple times per day requiring hard reboot.

  5. added a commit that references this issue on Feb 20, 2026
    9d77518
  6. thdxr commented on Apr 2, 2026

    @thdxr
    Member

    Closing in favor of #20695 where we're collecting all memory-related problems. Please follow that issue for updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

perfIndicates a performance issue or need for optimization

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions