-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Description
name: Bug Report
description: Potential FileSystemWatcher leak in FileWatcher/CodeIndexManager
labels: ["bug", "memory-leak", "guaranteed", "code-index", "auto-generated"]
Thanks for your report! Please check existing issues first:
π https://github.com/RooCodeInc/Roo-Code/issues
App Version
N/A (Static Analysis - Detected in file-watcher_93)
API Provider
Not Applicable / Other
Model Used
N/A (Core Extension Service - Code Indexing)
π Steps to Reproduce
- Setup: Roo Code VS Code extension is active.
- Exact actions:
- The
FileWatcherclass creates avscode.workspace.createFileSystemWatcherin itsinitializemethod. This watcher is stored inthis.fileWatcher. - The
FileWatcherinstance is managed byCodeIndexOrchestrator, which is managed byCodeIndexManager. - A scenario occurs where
CodeIndexManager.dispose()is not called, or fails to complete, during extension deactivation or due to an unhandled error.
- The
- What happened after each step:
- If
CodeIndexManager.dispose()is not successfully executed, the disposal chain (CodeIndexManager->CodeIndexOrchestrator->FileWatcher) is broken. - The
FileSystemWatcherinstance withinFileWatcheris not disposed. - The undisposed watcher continues to consume system resources, leading to a leak.
- If
π¨ Where The Leak Happens - Failure Points
Scenario 1: Error in abortTask()
// If Task.abortTask() throws an error BEFORE reaching this line: this.rooIgnoreController?.dispose(); // This never executes
Scenario 2: ClineProvider Disposal Issues
// If ClineProvider.dispose() doesn't call removeClineFromStack()
// Or if removeClineFromStack() fails before calling cline.abortTask()
// The FileSystemWatcher remains active
Scenario 3: Orphaned Task Instances
// If a Task is created but never added to clineStack
// Or removed from clineStack without proper cleanup
// No disposal path exists
π§ The Problem Visualized
Task Created β RooIgnoreController Created β FileSystemWatcher Created
β β β
Task.abortTask() β RooIgnoreController.dispose() β watcher.dispose()
β β β
MUST BE CALLED MUST BE CALLED MUST HAPPEN
π₯ Outcome Summary
Expected FileSystemWatcher instances to be reliably disposed of when the extension deactivates or the code indexing feature is stopped. However, if the CodeIndexManager's disposal process is interrupted or skipped, the watcher can leak.
π Relevant Logs or Errors (Optional)
Summary:
The
FileWatcherclass creates avscode.workspace.createFileSystemWatcherin itsinitializemethod. The watcher is stored inthis.fileWatcher. Thedisposemethod ofFileWatchercorrectly callsthis.fileWatcher?.dispose().However, the
FileWatcherinstance itself is managed byCodeIndexOrchestrator, which in turn is managed byCodeIndexManager. IfCodeIndexManager.dispose()is not called, or ifCodeIndexOrchestrator.stopWatcher()(which callsfileWatcher.dispose()) is not called before the manager is disposed, theFileSystemWatcherwill leak.The
CodeIndexManageris a singleton tied to the workspace path and is added tocontext.subscriptionsinsrc/extension.ts. This means itsdisposemethod should be called on extension deactivation. The leak is guaranteed if there's any scenario whereCodeIndexManager.dispose()isn't called or ifCodeIndexOrchestrator.stopWatcher()isn't called before the manager's disposal.
The main concern is the FileSystemWatcher created in src/services/code-index/processors/file-watcher.ts around line 93.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status