microsoft / microsoft/monaco-editor

[Bug] False positive "potential listener LEAK detected"

Open
#4,865 3 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
46.8k
Forks
4.1k
Avg merge
17h 58m
Merged PRs (30d)
1

Description

Reproducible in vscode.dev or in VS Code Desktop?
  • Not reproducible in vscode.dev or VS Code Desktop
Reproducible in the monaco editor playground?
Monaco Editor Playground Link

Monaco playground link

Monaco Editor Playground Code
The key part is just adding this:


for (let i = 0; i < 200; ++i)
{
	monaco.editor.createModel("");
}
Reproduction Steps

Suppose the user has a project with 200 files in it. For this use case, a model must be created for every script file for features like 'Rename' and 'Find all references' to work correctly. It is not possible to lazy-create or dispose inactive models in this case: they must all be created simultaneously for such cross-file features to work as expected.

VS Code can open a project with 200 files just fine. However if you create 200 models with Monaco, it fails.

Actual (Problematic) Behavior

Throws an error Uncaught Error: [001] potential listener LEAK detected, having 200 listeners already.

Expected Behavior

Not to throw an error, or for the limit of 200 to at least be configurable.

Additional Context

This was previously filed at #3895 but it was closed without being resolved we just ran in to it again when integrating Monaco in to Construct. The previous comment was "that shouldn't happen in real applications", but as I've described, it really does happen and is a legitimate use case that VS Code can handle fine and only Monaco has an issue with.

The limit appears to come from leakWarningThreshold in the source code, but this limit is not configurable. For the time being we have to edit the source code to make the number 200 bigger. If there was at least an API to specify that, we wouldn't have to edit the source in our distribution.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue from the linked Monaco playground with 200 calls to monaco.editor.createModel(""). Start by locating leakWarningThreshold and the listener-registration path that emits the warning. Done means the valid multi-model use case no longer throws, or the threshold can be configured through a supported API.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.