Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

align max listeners check with VS Code extensions' expectations #7508

Merged
merged 3 commits into from
Apr 8, 2020

Conversation

akosyakov
Copy link
Member

@akosyakov akosyakov commented Apr 6, 2020

What it does

Since we support multi root workspaces and VS Code extensions we started seeing many false positive leaking emitters. This PR addresses it in similar approach as VS Code does:

  • increase the max listeners threshold to 175 listeners
  • only warn on first exceed and then every time the limit is exceeded by 50% again. So only real leaking emitter will be reported more than once.
  • report the top stack trace

How to test

Review checklist

Reminder for reviewers

@akosyakov akosyakov added the core issues related to the core of the application label Apr 6, 2020
@akosyakov
Copy link
Member Author

I have not time to test it myself yet, I will do later today if no one does it before.

@akosyakov akosyakov added the vscode issues related to VSCode compatibility label Apr 6, 2020
Copy link
Contributor

@RomanNikitenko RomanNikitenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@akosyakov
I don't see the warning at starting Theia now, but I got it after using Peek widget and switching between editors:

peek_widget_memory_leak

I'll try at debugging as I mentioned here #7506 (review)

@RomanNikitenko
Copy link
Contributor

Using these changes I can not reproduce the use case described here #7506 (review)

@akosyakov
Copy link
Member Author

@RomanNikitenko about onPreferencesChanged, I want to remove custom threshold 64, but I have to understand whether it is false positive (which are expected sometimes) or it is a real leak (looking at stack trace it is not). I am struggling to reproduce. Do you know how many editors did you open to reproduce? Could you do it reliably? If so then how?

@akosyakov
Copy link
Member Author

ok, I found a pretty serious memory leak: DisposableCollection.onDispose is never disposed, so clients like editor.onDispose(() => { lalal }) actually keeping a reference to an editor, the same for other places where we delegate to DisposableCollection.onDispose.

There is a problem that DisposableCollection can be reused many times, so if we dispose onDispose then on next dispose there won't be an event. Looking at clients though I could not find a single expecting second event, so it seems to be alright.

I'm going to dispose this event on first dispose. If we break some clients they should be fixed then. cc @svenefftinge @AlexTugarev

@akosyakov
Copy link
Member Author

Monaco editors are also leaking somehow via our quick open controller:

Screenshot 2020-04-06 at 20 26 25

@RomanNikitenko
Copy link
Contributor

RomanNikitenko commented Apr 6, 2020

@akosyakov

I am struggling to reproduce. Do you know how many editors did you open to reproduce? Could you do it reliably? If so then how?

Yes, I can reproduce it. I had about 10 open editors then went to TaskService -> @inject(WidgetManager) , used Peek -> Peek References, opened 8 editors to get the error.
I refreshed a page to have a clean state before testing.

error_memory_leak

@akosyakov akosyakov force-pushed the akosyakov/error-possible-emitter-6659 branch from c85a1d9 to be2bc5d Compare April 6, 2020 18:30
@RomanNikitenko
Copy link
Contributor

RomanNikitenko commented Apr 6, 2020

@akosyakov
btw: looks like I caught the error related to serializeURI at testing memory leak, you can see it on the video of my previous comment.

uri_error

@akosyakov
Copy link
Member Author

@RomanNikitenko i think you stumbled over #6733

@akosyakov akosyakov force-pushed the akosyakov/error-possible-emitter-6659 branch from be2bc5d to 2bb5dd9 Compare April 7, 2020 08:14
@akosyakov akosyakov added the monaco issues related to monaco label Apr 7, 2020
@akosyakov
Copy link
Member Author

akosyakov commented Apr 7, 2020

Leaking editors should be fixed by removing custom closures on editor dispose. They used to capture an editor instance.

One can verify by:

  • opening multiple editors
  • using quick open command and peek references
  • closing all editors
  • triggering garbage collection
  • taking the heap shanshot
  • and checking that there is no many MonacoEditor instances anymore

@akosyakov akosyakov changed the title WIP align max listeners check with VS Code extensions' expectations align max listeners check with VS Code extensions' expectations Apr 7, 2020
@akosyakov akosyakov requested a review from kittaakos April 7, 2020 10:20
@akosyakov
Copy link
Member Author

@RomanNikitenko Could you check again please? I've fixed leaking editors.

@RomanNikitenko RomanNikitenko self-requested a review April 7, 2020 13:02
Copy link
Contributor

@RomanNikitenko RomanNikitenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested using this way
I can not reproduce it after update!

@RomanNikitenko
Copy link
Contributor

Also tested using the heap snapshots.
I had 24 MonacoEditor objects when editors were open.
and 2 objects after closing them.
One of them is MonacoDiffEditor, can not recognize another one

heap_snapshots

@akosyakov
Copy link
Member Author

@RomaNikitenko sometimes widgets are hold temporarily by some contribution, for instance, the toolbar holds a reference to latest current widget. But it is not a real leak, since a reference gets removed when another widget becomes current.

@RomanNikitenko
Copy link
Contributor

RomanNikitenko commented Apr 7, 2020

for instance, the toolbar holds a reference to latest current widget.

agree, I had the same idea (reference to latest editor widget) when faced with it

@akosyakov akosyakov merged commit e1840a3 into master Apr 8, 2020
@akosyakov akosyakov deleted the akosyakov/error-possible-emitter-6659 branch April 8, 2020 06:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core issues related to the core of the application monaco issues related to monaco vscode issues related to VSCode compatibility
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error: Possible Emitter memory leak detected
2 participants