Skip to content

NativePythonFinder: Resource leaks in dispose() - worker pool and disposables not cleaned up #1141

@karthiknadig

Description

@karthiknadig

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

Metadata

Metadata

Assignees

Labels

area-environmentEnvironment, interpreter related issues.bugIssue identified by VS Code Team member as probable bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions