From 08bca485860ff8d32d318c7901afb14a91a76f48 Mon Sep 17 00:00:00 2001 From: Alex Ross Date: Wed, 16 Jun 2021 16:11:08 +0200 Subject: [PATCH] Fix race that causes auto port forwarding setting to be ignored (#126481) * Fix race in proc based port finding * Check port auto forward setting after waiting Fixes microsoft/vscode-remote-release#5208 --- .../contrib/remote/browser/remoteExplorer.ts | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/vs/workbench/contrib/remote/browser/remoteExplorer.ts b/src/vs/workbench/contrib/remote/browser/remoteExplorer.ts index db88121bccbdd..0ba9d54a78e57 100644 --- a/src/vs/workbench/contrib/remote/browser/remoteExplorer.ts +++ b/src/vs/workbench/contrib/remote/browser/remoteExplorer.ts @@ -488,7 +488,15 @@ class ProcAutomaticPortForwarding extends Disposable { ) { super(); this.notifier = new OnAutoForwardedAction(notificationService, remoteExplorerService, openerService, externalOpenerService, tunnelService, hostService, logService); - this._register(configurationService.onDidChangeConfiguration(async (e) => { + this.initialize(); + } + + private async initialize() { + if (!this.remoteExplorerService.tunnelModel.environmentTunnelsSet) { + await new Promise(resolve => this.remoteExplorerService.tunnelModel.onEnvironmentTunnelsSet(() => resolve())); + } + + this._register(this.configurationService.onDidChangeConfiguration(async (e) => { if (e.affectsConfiguration(PORT_AUTO_FORWARD_SETTING)) { await this.startStopCandidateListener(); } @@ -524,14 +532,13 @@ class ProcAutomaticPortForwarding extends Disposable { this.portsFeatures.dispose(); } - if (!this.remoteExplorerService.tunnelModel.environmentTunnelsSet) { - await new Promise(resolve => this.remoteExplorerService.tunnelModel.onEnvironmentTunnelsSet(() => resolve())); - } - // Capture list of starting candidates so we don't auto forward them later. await this.setInitialCandidates(); - this.candidateListener = this._register(this.remoteExplorerService.tunnelModel.onCandidatesChanged(this.handleCandidateUpdate, this)); + // Need to check the setting again, since it may have changed while we waited for the initial candidates to be set. + if (this.configurationService.getValue(PORT_AUTO_FORWARD_SETTING)) { + this.candidateListener = this._register(this.remoteExplorerService.tunnelModel.onCandidatesChanged(this.handleCandidateUpdate, this)); + } } private async setInitialCandidates() {