opencode
opencode copied to clipboard
Memory leak: LSP client diagnostics and files maps not cleared on shutdown
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:
- Memory retention - Diagnostics data for closed files remains in memory
- Stale data - If the same LSP server is reconnected, old diagnostics may persist
- 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