Skip to content

Commit 08bca48

Browse files
authored
Fix race that causes auto port forwarding setting to be ignored (microsoft#126481)
* Fix race in proc based port finding * Check port auto forward setting after waiting Fixes microsoft/vscode-remote-release#5208
1 parent 2650c2e commit 08bca48

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,15 @@ class ProcAutomaticPortForwarding extends Disposable {
488488
) {
489489
super();
490490
this.notifier = new OnAutoForwardedAction(notificationService, remoteExplorerService, openerService, externalOpenerService, tunnelService, hostService, logService);
491-
this._register(configurationService.onDidChangeConfiguration(async (e) => {
491+
this.initialize();
492+
}
493+
494+
private async initialize() {
495+
if (!this.remoteExplorerService.tunnelModel.environmentTunnelsSet) {
496+
await new Promise<void>(resolve => this.remoteExplorerService.tunnelModel.onEnvironmentTunnelsSet(() => resolve()));
497+
}
498+
499+
this._register(this.configurationService.onDidChangeConfiguration(async (e) => {
492500
if (e.affectsConfiguration(PORT_AUTO_FORWARD_SETTING)) {
493501
await this.startStopCandidateListener();
494502
}
@@ -524,14 +532,13 @@ class ProcAutomaticPortForwarding extends Disposable {
524532
this.portsFeatures.dispose();
525533
}
526534

527-
if (!this.remoteExplorerService.tunnelModel.environmentTunnelsSet) {
528-
await new Promise<void>(resolve => this.remoteExplorerService.tunnelModel.onEnvironmentTunnelsSet(() => resolve()));
529-
}
530-
531535
// Capture list of starting candidates so we don't auto forward them later.
532536
await this.setInitialCandidates();
533537

534-
this.candidateListener = this._register(this.remoteExplorerService.tunnelModel.onCandidatesChanged(this.handleCandidateUpdate, this));
538+
// Need to check the setting again, since it may have changed while we waited for the initial candidates to be set.
539+
if (this.configurationService.getValue(PORT_AUTO_FORWARD_SETTING)) {
540+
this.candidateListener = this._register(this.remoteExplorerService.tunnelModel.onCandidatesChanged(this.handleCandidateUpdate, this));
541+
}
535542
}
536543

537544
private async setInitialCandidates() {

0 commit comments

Comments
 (0)