Summary
The NativePythonFinderImpl class has resource management issues that can lead to memory leaks and orphaned processes.
Issues Identified
1. Worker Pool Not Disposed
In nativePythonFinder.ts, the dispose() method only disposes the connection but not the worker pool:
public dispose() {
this.connection.dispose();
// BUG: this.pool is never stopped/disposed!
}
The worker pool created at construction (line ~112) runs indefinitely with workers waiting for queue items. When the finder is disposed, these workers remain active, blocked on promises that will never resolve.
Fix:
public dispose() {
this.pool.stop(); // Stop worker pool first
this.connection.dispose();
}
2. Disposables in start() Not Tracked
In the start() method (lines 206-275), disposables are created and pushed to a local array:
const disposables: Disposable[] = [];
// ... disposables.push(...)
disposables.push(
connection,
connection.onError(...),
connection.onNotification('log', ...),
// etc.
);
These disposables are only disposed when connection.onClose() fires. If the connection is disposed directly (or never properly established), these subscriptions leak.
Impact: Event handlers for log, telemetry, etc. may remain registered even after the finder is disposed.
Fix: Track disposables at class level and dispose them in dispose():
private readonly disposables: Disposable[] = [];
public dispose() {
this.pool.stop();
this.disposables.forEach(d => d.dispose());
this.connection.dispose();
}
Files to Modify
src/managers/common/nativePythonFinder.ts
Related
Summary
The
NativePythonFinderImplclass has resource management issues that can lead to memory leaks and orphaned processes.Issues Identified
1. Worker Pool Not Disposed
In
nativePythonFinder.ts, thedispose()method only disposes the connection but not the worker pool:The worker pool created at construction (line ~112) runs indefinitely with workers waiting for queue items. When the finder is disposed, these workers remain active, blocked on promises that will never resolve.
Fix:
2. Disposables in
start()Not TrackedIn the
start()method (lines 206-275), disposables are created and pushed to a local array:These disposables are only disposed when
connection.onClose()fires. If the connection is disposed directly (or never properly established), these subscriptions leak.Impact: Event handlers for
log,telemetry, etc. may remain registered even after the finder is disposed.Fix: Track disposables at class level and dispose them in
dispose():Files to Modify
src/managers/common/nativePythonFinder.tsRelated