Skip to content

Commit adf14a0

Browse files
authored
remote - fix some leaks (microsoft#247707)
1 parent edb1a9b commit adf14a0

File tree

3 files changed

+21
-20
lines changed

3 files changed

+21
-20
lines changed

src/vs/workbench/contrib/remote/browser/remote.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import { IDialogService } from '../../../../platform/dialogs/common/dialogs.js';
3333
import { ReconnectionWaitEvent, PersistentConnectionEventType } from '../../../../platform/remote/common/remoteAgentConnection.js';
3434
import Severity from '../../../../base/common/severity.js';
3535
import { ReloadWindowAction } from '../../../browser/actions/windowActions.js';
36-
import { Disposable, IDisposable } from '../../../../base/common/lifecycle.js';
36+
import { Disposable, IDisposable, MutableDisposable } from '../../../../base/common/lifecycle.js';
3737
import { SwitchRemoteViewItem } from './explorerViewItems.js';
3838
import { isStringArray } from '../../../../base/common/types.js';
3939
import { HelpInformation, IRemoteExplorerService } from '../../../services/remote/common/remoteExplorerService.js';
@@ -120,7 +120,7 @@ interface IHelpItem {
120120
handleClick(): Promise<void>;
121121
}
122122

123-
class HelpModel {
123+
class HelpModel extends Disposable {
124124
items: IHelpItem[] | undefined;
125125

126126
constructor(
@@ -133,8 +133,10 @@ class HelpModel {
133133
private workspaceContextService: IWorkspaceContextService,
134134
private walkthroughsService: IWalkthroughsService
135135
) {
136+
super();
137+
136138
this.updateItems();
137-
viewModel.onDidChangeHelpInformation(() => this.updateItems());
139+
this._register(viewModel.onDidChangeHelpInformation(() => this.updateItems()));
138140
}
139141

140142
private createHelpItemValue(info: HelpInformation, infoKey: Exclude<keyof HelpInformation, 'extensionDescription' | 'remoteName' | 'virtualWorkspace'>) {
@@ -491,7 +493,7 @@ class HelpPanel extends ViewPane {
491493
}
492494
);
493495

494-
const model = new HelpModel(this.viewModel, this.openerService, this.quickInputService, this.commandService, this.remoteExplorerService, this.environmentService, this.workspaceContextService, this.walkthroughsService);
496+
const model = this._register(new HelpModel(this.viewModel, this.openerService, this.quickInputService, this.commandService, this.remoteExplorerService, this.environmentService, this.workspaceContextService, this.walkthroughsService));
495497

496498
this.tree.setInput(model);
497499

@@ -545,9 +547,9 @@ class RemoteViewPaneContainer extends FilterViewPaneContainer implements IViewMo
545547
super(VIEWLET_ID, remoteExplorerService.onDidChangeTargetType, configurationService, layoutService, telemetryService, storageService, instantiationService, themeService, contextMenuService, extensionService, contextService, viewDescriptorService, logService);
546548
this.addConstantViewDescriptors([this.helpPanelDescriptor]);
547549
this._register(this.remoteSwitcher = this.instantiationService.createInstance(SwitchRemoteViewItem));
548-
this.remoteExplorerService.onDidChangeHelpInformation(extensions => {
550+
this._register(this.remoteExplorerService.onDidChangeHelpInformation(extensions => {
549551
this._setHelpInformation(extensions);
550-
});
552+
}));
551553

552554
this._setHelpInformation(this.remoteExplorerService.helpInformation);
553555
const viewsRegistry = Registry.as<IViewsRegistry>(Extensions.ViewsRegistry);
@@ -804,7 +806,7 @@ export class RemoteAgentConnectionStatusListener extends Disposable implements I
804806

805807
let visibleProgress: VisibleProgress | null = null;
806808
let reconnectWaitEvent: ReconnectionWaitEvent | null = null;
807-
let disposableListener: IDisposable | null = null;
809+
const disposableListener = this._register(new MutableDisposable());
808810

809811
function showProgress(location: ProgressLocation.Dialog | ProgressLocation.Notification | null, buttons: { label: string; callback: () => void }[], initialReport: string | null = null): VisibleProgress {
810812
if (visibleProgress) {
@@ -886,13 +888,10 @@ export class RemoteAgentConnectionStatusListener extends Disposable implements I
886888
// ReconnectionWait -> ReconnectionRunning
887889
// ReconnectionRunning -> ConnectionGain, ReconnectionPermanentFailure
888890

889-
connection.onDidStateChange((e) => {
891+
this._register(connection.onDidStateChange((e) => {
890892
visibleProgress?.stopTimer();
893+
disposableListener.clear();
891894

892-
if (disposableListener) {
893-
disposableListener.dispose();
894-
disposableListener = null;
895-
}
896895
switch (e.type) {
897896
case PersistentConnectionEventType.ConnectionLost:
898897
reconnectionToken = e.reconnectionToken;
@@ -961,7 +960,7 @@ export class RemoteAgentConnectionStatusListener extends Disposable implements I
961960
visibleProgress.report(nls.localize('reconnectionRunning', "Disconnected. Attempting to reconnect..."));
962961

963962
// Register to listen for quick input is opened
964-
disposableListener = quickInputService.onShow(() => {
963+
disposableListener.value = quickInputService.onShow(() => {
965964
// Need to move from dialog if being shown and user needs to type in a prompt
966965
if (visibleProgress && visibleProgress.location === ProgressLocation.Dialog) {
967966
visibleProgress = showProgress(ProgressLocation.Notification, [reloadButton], visibleProgress.lastReport);
@@ -1048,7 +1047,7 @@ export class RemoteAgentConnectionStatusListener extends Disposable implements I
10481047
hideProgress();
10491048
break;
10501049
}
1051-
});
1050+
}));
10521051
}
10531052
}
10541053
}

src/vs/workbench/contrib/remote/electron-sandbox/remote.contribution.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,22 +65,24 @@ class RemoteAgentDiagnosticListener implements IWorkbenchContribution {
6565
}
6666
}
6767

68-
class RemoteExtensionHostEnvironmentUpdater implements IWorkbenchContribution {
68+
class RemoteExtensionHostEnvironmentUpdater extends Disposable implements IWorkbenchContribution {
6969
constructor(
7070
@IRemoteAgentService remoteAgentService: IRemoteAgentService,
7171
@IRemoteAuthorityResolverService remoteResolverService: IRemoteAuthorityResolverService,
7272
@IExtensionService extensionService: IExtensionService
7373
) {
74+
super();
75+
7476
const connection = remoteAgentService.getConnection();
7577
if (connection) {
76-
connection.onDidStateChange(async e => {
78+
this._register(connection.onDidStateChange(async e => {
7779
if (e.type === PersistentConnectionEventType.ConnectionGain) {
7880
const resolveResult = await remoteResolverService.resolveAuthority(connection.remoteAuthority);
7981
if (resolveResult.options && resolveResult.options.extensionHostEnv) {
8082
await extensionService.setRemoteEnvironment(resolveResult.options.extensionHostEnv);
8183
}
8284
}
83-
});
85+
}));
8486
}
8587
}
8688
}

src/vs/workbench/services/extensions/electron-sandbox/nativeExtensionService.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -393,12 +393,12 @@ export class NativeExtensionService extends AbstractExtensionService implements
393393
// monitor for breakage
394394
const connection = this._remoteAgentService.getConnection();
395395
if (connection) {
396-
connection.onDidStateChange(async (e) => {
396+
this._register(connection.onDidStateChange(async (e) => {
397397
if (e.type === PersistentConnectionEventType.ConnectionLost) {
398398
this._remoteAuthorityResolverService._clearResolvedAuthority(remoteAuthority);
399399
}
400-
});
401-
connection.onReconnecting(() => this._resolveAuthorityAgain());
400+
}));
401+
this._register(connection.onReconnecting(() => this._resolveAuthorityAgain()));
402402
}
403403

404404
// fetch the remote environment

0 commit comments

Comments
 (0)