Fix leak/exception and links becoming bricked within the terminal #203915
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes the long standing issue where links suddenly break in the terminal (#184046) as well as a few leak issues, one of which could trigger an exception which would likely cause other problems.
I reproduced the primary issue by using the following code on the exthost side to simulate an extension registering and disposing a single link provider:
This is why the issue was so hard to reproduce in OSS since it happened when extensions did something that was somewhat unexpected. After putting this in place it became clear that the problem was related to the clunky re-creation of
TerminalLinkManager
when the extension host disposes of all of its link providers here:vscode/src/vs/workbench/contrib/terminalContrib/links/browser/terminal.links.contribution.ts
Lines 73 to 76 in ef40932
Going deeper I found that xterm.js is holding onto disposed link adapters that were registered here:
vscode/src/vs/workbench/contrib/terminalContrib/links/browser/terminalLinkManager.ts
Line 351 in ef40932
vscode/src/vs/workbench/contrib/terminalContrib/links/browser/terminalLinkManager.ts
Line 360 in ef40932
So that fix was a matter of correctly disposing them when the link manager was replaced.
The
TerminalLinkManager
disposal is still in place and I noticed that when that happens it causes links to disappear, so it could be related to another issue where link underlines flicker. This is deferred though as this PR is complicated enough and that would need a new upstream API.Fixes #184046
Fixes #203437