Skip to content

Conversation

@sauerdaniel
Copy link
Contributor

@sauerdaniel sauerdaniel commented Jan 17, 2026

Summary

Properly clean up LSP client resources when the underlying LSP server process disconnects or exits.

Fixes #9143
Relates to #5363

Problem

When an LSP client shuts down, the diagnostics Map and files object are not cleared. This can cause:

  1. Memory retention from diagnostics data for closed files
  2. Stale data if the same LSP server reconnects
  3. Memory growth over multiple LSP reconnections

Solution

Add cleanup logic in the LSP client shutdown() method to:

  • Clear the diagnostics Map
  • Clear the files object

Changes

  • packages/opencode/src/lsp/client.ts - Add cleanup in shutdown() method

Testing

  • TypeScript compilation passes (bun turbo typecheck)
  • Unit tests pass (725 tests, 0 failures)
  • LSP client tests pass (3 tests)

Note: Manual LSP server disconnect testing was not performed.

Clear internal LSP client maps on shutdown to prevent memory leaks
in long-running sessions:
- Clear diagnostics Map (growing indefinitely with file edits)
- Clear files version tracking object
@github-actions
Copy link
Contributor

The following comment was made by an LLM, it may be inaccurate:

Potential Duplicate Found

PR #7050: "fix: add LRU eviction to LSP client file and diagnostics tracking"

Why it's related: This PR also addresses memory management issues with the LSP client's diagnostics and files tracking. While PR #9144 takes a shutdown-based cleanup approach, PR #7050 implements LRU (Least Recently Used) eviction as a solution to the same underlying problem of memory retention in the LSP client. They may be addressing overlapping concerns about the diagnostics Map and files object accumulation.

You may want to check if PR #7050 was merged and whether it already resolves the issues mentioned in #9143 and #5363.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant