-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix(core): Free WASM resources and cap MCP caches to prevent memory leaks #1379
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,11 +6,19 @@ import type { CallToolResult } from '@modelcontextprotocol/sdk/types.js'; | |
| import { generateTreeString } from '../../core/file/fileTreeGenerate.js'; | ||
| import type { ProcessedFile } from '../../core/file/fileTypes.js'; | ||
|
|
||
| // Map to store generated output files | ||
| // Map to store generated output files. Capped to prevent unbounded growth | ||
| // in long-running MCP server processes. | ||
| const MAX_REGISTRY_SIZE = 100; | ||
| const outputFileRegistry = new Map<string, string>(); | ||
|
|
||
| // Register an output file | ||
| // Register an output file, evicting the oldest entry if at capacity | ||
| export const registerOutputFile = (id: string, filePath: string): void => { | ||
| if (outputFileRegistry.size >= MAX_REGISTRY_SIZE) { | ||
| const oldestKey = outputFileRegistry.keys().next().value; | ||
| if (oldestKey !== undefined) { | ||
| outputFileRegistry.delete(oldestKey); | ||
| } | ||
| } | ||
|
Comment on lines
+16
to
+21
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While evicting entries from |
||
| outputFileRegistry.set(id, filePath); | ||
| }; | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
gitAvailabilityCache(declared at line 15) is also a module-levelMapthat grows without limit as different directories are processed. To fully address the memory leak concerns in long-running processes, this cache should also be capped using a similar FIFO eviction strategy asfileChangeCountsCache. This is particularly relevant becausecwdchanges for every remote repository packing operation.