opencode icon indicating copy to clipboard operation
opencode copied to clipboard

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

Open sauerdaniel opened this issue 13 hours ago • 1 comments

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

sauerdaniel avatar Jan 17 '26 23:01 sauerdaniel