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

chore - disposable tracker can differentiate between weak and strong leak #239322

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

jrieken
Copy link
Member

@jrieken jrieken commented Jan 31, 2025

No description provided.

@jrieken jrieken self-assigned this Jan 31, 2025
@jrieken jrieken enabled auto-merge (squash) January 31, 2025 13:48
@vs-code-engineering vs-code-engineering bot added this to the February 2025 milestone Jan 31, 2025
Tyriar
Tyriar previously approved these changes Jan 31, 2025
Tyriar
Tyriar previously approved these changes Jan 31, 2025
@Tyriar
Copy link
Member

Tyriar commented Jan 31, 2025

Oh still failing too

@jrieken
Copy link
Member Author

jrieken commented Jan 31, 2025

Oh still failing too

I know... There is plenty of bogous tests. Throwing the towel, it's not feasible.

@hediet @connor4312 I believe there is something fundamentally wrong with ensureNoDisposablesAreLeakedInTestSuite. Disposables like this case (which is a popular pattern) aren't tracked. When the store get's constructed there is no tracker yet. This PR wants to introduce the notion of a weak and hard leak, e.g. an empty disposable store that's leaked isn't as bad as leaked true disposable. This means the tracker is invoked multiple times for the same object (like on first add of the store) and that unveils all the ugly cases from above.

I am drafting this PR and give it to you, maybe there is something clever that can be done. Otherwise it isn't worth the effort and every leak is a bad leak

@jrieken jrieken marked this pull request as draft January 31, 2025 17:35
auto-merge was automatically disabled January 31, 2025 17:35

Pull request was converted to draft

@Tyriar
Copy link
Member

Tyriar commented Feb 2, 2025

I believe there is something fundamentally wrong with ensureNoDisposablesAreLeakedInTestSuite. Disposables like this case (which is a popular pattern) aren't tracked.

This was always been how it's worked and was known to at least some people. Anything created before you call ensure will not be tracked, sometimes I think this was beneficial to people in adopting it since you could stick the ensure call after setup and not need to deal with making sure just test setup code was not being leaked (eg. store.add on a bunch of services). I can't remember if it was called it out, but I assumed it was known by most since they explicitly put the call after all the tests which is a weird place to put it for no reason.

If we want to "fix" this, I think we'd need another team-wide debt task with an eslint rule that forces the ensure call to be the first call inside suite so that it's setup and teardown always come first.

suite('Workbench - TerminalInstance', () => {
const store = ensureNoDisposablesAreLeakedInTestSuite();

For the case where you want a teardown to run before leaked disposables are detected you could then use store.add(toDisposable(myTeardown))


For the case you mentioned specifically, can't you just change that line to store = ensureNoDisposablesAreLeakedInTestSuite(); and remove the disposables.clear(); in teardown?

const disposables = new DisposableStore();

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