Skip to content

Memory leak: LSP client diagnostics and files maps not cleared on shutdown #9143

@sauerdaniel

Description

@sauerdaniel

Problem

When an LSP client shuts down, the diagnostics Map and files object are not cleared in the shutdown() method of LSPClient. This can cause:

  1. Memory retention - Diagnostics data for closed files remains in memory
  2. Stale data - If the same LSP server is reconnected, old diagnostics may persist
  3. Memory growth - Over multiple LSP reconnections, maps accumulate entries

Code Location

packages/opencode/src/lsp/client.ts - The shutdown() method closes the connection but doesn't clear internal state.

Proposed Solution

Add cleanup calls in the shutdown() method:

diagnostics.clear()
for (const path in files) delete files[path]

Impact

  • Minimal change (2 lines)
  • Ensures clean state on LSP shutdown
  • Prevents memory growth from accumulated diagnostics

Relates to #5363

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