Skip to content

Commit

Permalink
Fix race that causes auto port forwarding setting to be ignored (#126481
Browse files Browse the repository at this point in the history
)

* Fix race in proc based port finding

* Check port auto forward setting after waiting

Fixes microsoft/vscode-remote-release#5208
  • Loading branch information
alexr00 authored Jun 16, 2021
1 parent 2650c2e commit 08bca48
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/vs/workbench/contrib/remote/browser/remoteExplorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>(resolve => this.remoteExplorerService.tunnelModel.onEnvironmentTunnelsSet(() => resolve()));
}

this._register(this.configurationService.onDidChangeConfiguration(async (e) => {
if (e.affectsConfiguration(PORT_AUTO_FORWARD_SETTING)) {
await this.startStopCandidateListener();
}
Expand Down Expand Up @@ -524,14 +532,13 @@ class ProcAutomaticPortForwarding extends Disposable {
this.portsFeatures.dispose();
}

if (!this.remoteExplorerService.tunnelModel.environmentTunnelsSet) {
await new Promise<void>(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() {
Expand Down

0 comments on commit 08bca48

Please sign in to comment.