You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Error] unhandlederror-potential listener LEAK detected, popular — webview/webviewElement #312367
ai-analyzedAI automation workflow has run an analysis of this issue and provided a comment.ai-generatedGenerated by AI automation workflowsbugIssue identified by VS Code Team member as probable bugerror-telemetryVS Code - Issues generated by telemetryinsiders-releasedPatch has been released in VS Code Insidersrecent-regression
Error at a.create (out/vs/workbench/workbench.desktop.main.js:403:18436) at _Ie._event (out/vs/workbench/workbench.desktop.main.js:405:2009) at Object.start (out/vs/workbench/workbench.desktop.main.js:5205:27934) at r$e.loadResource (out/vs/workbench/workbench.desktop.main.js:5205:27837)
PR #311844 ("Use proper streams for loading webview resources") introduced a ReadableStream-based path for streaming webview resources. Inside the start callback of each ReadableStream, a listener is added to token.onCancellationRequested (line 804 of webviewElement.ts). Since all resource loads share a single _resourceLoadingCts token per WebviewElement instance, loading many resources concurrently (e.g., a markdown preview with many images or videos) causes the listener count on the token's emitter to exceed the leak detection threshold, triggering this "popular" leak warning. The error affects all platforms (Mac, Windows, Linux) and has impacted ~1,247 users across 1,793 hits.
Introduced a new ReadableStream code path where each resource load subscribes to token.onCancellationRequested(close) on a shared CancellationTokenSource. Concurrent resource loads accumulate listeners on the same emitter, exceeding the leak detection threshold.
Code Flow
sequenceDiagram
participant WV as Webview iframe
participant WE as WebviewElement
participant RS as ReadableStream (per resource)
participant CT as CancellationToken (_resourceLoadingCts)
participant EM as Emitter (leak monitor)
WV->>WE: load-resource (×N concurrent)
loop For each resource
WE->>WE: loadResource(id, uri, opts, token)
WE->>RS: new ReadableStream({ start })
RS->>CT: token.onCancellationRequested(close)
Note over CT: Listener count += 1
end
Note over EM: ⚠️ Root cause:<br/>Listener count exceeds threshold<br/>(N concurrent loads on same token)
EM-->>EM: 💥 ListenerLeakError thrown:<br/>"potential listener LEAK detected, popular"
CancellationTokenSource creates an Emitter<void> without a custom leak threshold (line 84)
Repro Steps
Open VS Code Insiders (1.118.0+)
Create a Markdown file that references many local resources (e.g., 30+ images or videos)
Open the Markdown Preview
Observe the "potential listener LEAK detected, popular" error in telemetry/developer tools — the shared _resourceLoadingCts.token accumulates one listener per concurrent resource load
Approach: The core issue is that all concurrent resource loads share a single _resourceLoadingCts token and each adds a listener via token.onCancellationRequested(close) inside the ReadableStream.start callback. Two approaches:
Per-resource linked token (preferred): Create a child CancellationTokenSource linked to _resourceLoadingCts for each loadResource call. This isolates each resource's listener to its own token emitter. Dispose the child token when the stream completes or errors.
Raise the leak threshold: Create the _resourceLoadingCts emitter with a higher leakWarningThreshold to tolerate many concurrent resource loads. This is simpler but masks genuine leaks.
Recommended Owner
@mjbvz — culprit commit author (PR #311844) and webview area owner
ai-analyzedAI automation workflow has run an analysis of this issue and provided a comment.ai-generatedGenerated by AI automation workflowsbugIssue identified by VS Code Team member as probable bugerror-telemetryVS Code - Issues generated by telemetryinsiders-releasedPatch has been released in VS Code Insidersrecent-regression
Activity
[-][Error] unhandlederror-potential listener LEAK detected, popular[/-][+][Error] unhandlederror-potential listener LEAK detected, popular — webview/webviewElement[/+]vs-code-engineering commentedon Apr 24, 2026
Regression Details
newDeminified Stack Summary
The listener leak originates from
webviewElement.ts:loadResource(line 794/804). The subscription chain is:event.ts→ leak monitoring fireswebviewElement.ts→loadResourcesubscribes to an eventThis is a popular leak — no single subscriber dominates; the webview element's event emitter has accumulated too many listeners across sessions.
vs-code-engineering commentedon Apr 24, 2026
🔍 Error Investigation
Summary
PR #311844 ("Use proper streams for loading webview resources") introduced a
ReadableStream-based path for streaming webview resources. Inside thestartcallback of eachReadableStream, a listener is added totoken.onCancellationRequested(line 804 ofwebviewElement.ts). Since all resource loads share a single_resourceLoadingCtstoken perWebviewElementinstance, loading many resources concurrently (e.g., a markdown preview with many images or videos) causes the listener count on the token's emitter to exceed the leak detection threshold, triggering this "popular" leak warning. The error affects all platforms (Mac, Windows, Linux) and has impacted ~1,247 users across 1,793 hits.Culprit Commit
b980ef34@mjbvzReadableStreamcode path where each resource load subscribes totoken.onCancellationRequested(close)on a sharedCancellationTokenSource. Concurrent resource loads accumulate listeners on the same emitter, exceeding the leak detection threshold.Code Flow
sequenceDiagram participant WV as Webview iframe participant WE as WebviewElement participant RS as ReadableStream (per resource) participant CT as CancellationToken (_resourceLoadingCts) participant EM as Emitter (leak monitor) WV->>WE: load-resource (×N concurrent) loop For each resource WE->>WE: loadResource(id, uri, opts, token) WE->>RS: new ReadableStream({ start }) RS->>CT: token.onCancellationRequested(close) Note over CT: Listener count += 1 end Note over EM: ⚠️ Root cause:<br/>Listener count exceeds threshold<br/>(N concurrent loads on same token) EM-->>EM: 💥 ListenerLeakError thrown:<br/>"potential listener LEAK detected, popular"Affected Files
src/vs/workbench/contrib/webview/browser/webviewElement.tsloadResource()(line 794) createsReadableStreamwhosestartcallback subscribes to shared cancellation token (line 804)src/vs/base/common/event.tsLeakageMonitorfiresListenerLeakErrorwhen threshold exceeded (line 1068, 1272)src/vs/base/common/cancellation.tsCancellationTokenSourcecreates anEmitter<void>without a custom leak threshold (line 84)Repro Steps
_resourceLoadingCts.tokenaccumulates one listener per concurrent resource loadFix Proposal
Fix location:
src/vs/workbench/contrib/webview/browser/webviewElement.ts→loadResource()Approach: The core issue is that all concurrent resource loads share a single
_resourceLoadingCtstoken and each adds a listener viatoken.onCancellationRequested(close)inside theReadableStream.startcallback. Two approaches:Per-resource linked token (preferred): Create a child
CancellationTokenSourcelinked to_resourceLoadingCtsfor eachloadResourcecall. This isolates each resource's listener to its own token emitter. Dispose the child token when the stream completes or errors.Raise the leak threshold: Create the
_resourceLoadingCtsemitter with a higherleakWarningThresholdto tolerate many concurrent resource loads. This is simpler but masks genuine leaks.Recommended Owner
@mjbvz— culprit commit author (PR #311844) and webview area ownermjbvz commentedon Apr 24, 2026
Likely not an actual leak since we dispose these but lets try to fix this
Don't add listener for webview webview resource load