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

adopt ensureNoDisposablesLeaked in code action model tests #209279

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

justschen
Copy link
Contributor

@justschen justschen commented Apr 1, 2024

regarding: #200091

cc. @mjbvz

rzhao271
rzhao271 previously approved these changes Apr 1, 2024
@justschen justschen enabled auto-merge (squash) April 1, 2024 18:00
@justschen
Copy link
Contributor Author

looks like there were some leaks 👎

Tyriar
Tyriar previously approved these changes Apr 1, 2024
@@ -229,7 +231,7 @@ export class CodeActionModel extends Disposable {

const actions = createCancelablePromise(async token => {
if (this._settingEnabledNearbyQuickfixes() && trigger.trigger.type === CodeActionTriggerType.Invoke && (trigger.trigger.triggerAction === CodeActionTriggerSource.QuickFix || trigger.trigger.filter?.include?.contains(CodeActionKind.QuickFix))) {
const codeActionSet = await getCodeActions(this._registry, model, trigger.selection, trigger.trigger, Progress.None, token);
const codeActionSet = this.disposables.add(await getCodeActions(this._registry, model, trigger.selection, trigger.trigger, Progress.None, token));
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this introduces a leak as items are added to disposables but never removed

Instead try to make sure the old disposable values are released once a new set of values come in

Copy link
Contributor

Choose a reason for hiding this comment

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

That sounds like something for a DisposableStore and/or a MutableDisposable

this._signalChange(selection ? { trigger, selection } : undefined);
} finally {
// dispose after finishing (and after our _delay has passed)
setTimeout(() => this.dispose(), 300);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This seems fishy. You rarely want to call dispose directly like this as using the object should no longer be used after it has been disposed of . It looks like this object is meant to hang around for a while

What object was getting reported as leaked?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, this is the stack trace:

(shared with 1/2 leaks) at trackDisposable@http://localhost:58253/960ce1ff9eb3ef82c943175eaac845ed/out/vs/base/common/lifecycle.js:46:21
(shared with 1/2 leaks) at trackDisposable@http://localhost:58253/960ce1ff9eb3ef82c943175eaac845ed/out/vs/base/common/lifecycle.js:183:43
(shared with 1/2 leaks) at Disposable@http://localhost:58253/960ce1ff9eb3ef82c943175eaac845ed/out/vs/base/common/lifecycle.js:379:28
(shared with 1/2 leaks) at ManagedCodeActionSet@http://localhost:58253/960ce1ff9eb3ef82c943175eaac845ed/out/vs/editor/contrib/codeAction/browser/codeAction.js:49:13
(shared with 1/2 leaks) at getCodeActions@http://localhost:58253/960ce1ff9eb3ef82c943175eaac845ed/out/vs/editor/contrib/codeAction/browser/codeAction.js:119:20
(shared with 1/2 leaks) at async*_update/this._codeActionOracle.value</actions<@http://localhost:58253/960ce1ff9eb3ef82c943175eaac845ed/out/vs/editor/contrib/codeAction/browser/codeActionModel.js:269:79

codeActionModel.js:269 is the call to getCodeActions that we are returning.

agree, when disposing immediately, you would get the error i mentioned before, so the code action set and actions derived from it are seemingly used in the command later on as well, so disposing it early (even after no longer being used in the function) leads to issues. will continue to explore this as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants