Skip to content

Commit

Permalink
Use correct key for hybrid port unforwarding (#181005)
Browse files Browse the repository at this point in the history
* Use correct key for hybrid port unforwarding

* Use forwarded host for closing

* Delete key from this.autoForwarded
  • Loading branch information
alexr00 authored Apr 27, 2023
1 parent 1e29d60 commit 5886713
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/vs/workbench/contrib/remote/browser/remoteExplorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as nls from 'vs/nls';
import { Disposable, IDisposable } from 'vs/base/common/lifecycle';
import { IWorkbenchContribution } from 'vs/workbench/common/contributions';
import { Extensions, IViewContainersRegistry, IViewsRegistry, ViewContainer, ViewContainerLocation } from 'vs/workbench/common/views';
import { Attributes, AutoTunnelSource, IRemoteExplorerService, makeAddress, mapHasAddressLocalhostOrAllInterfaces, OnPortForward, PORT_AUTO_FORWARD_SETTING, PORT_AUTO_SOURCE_SETTING, PORT_AUTO_SOURCE_SETTING_HYBRID, PORT_AUTO_SOURCE_SETTING_OUTPUT, PORT_AUTO_SOURCE_SETTING_PROCESS, TUNNEL_VIEW_CONTAINER_ID, TUNNEL_VIEW_ID, TunnelSource } from 'vs/workbench/services/remote/common/remoteExplorerService';
import { Attributes, AutoTunnelSource, IRemoteExplorerService, makeAddress, mapHasAddressLocalhostOrAllInterfaces, OnPortForward, PORT_AUTO_FORWARD_SETTING, PORT_AUTO_SOURCE_SETTING, PORT_AUTO_SOURCE_SETTING_HYBRID, PORT_AUTO_SOURCE_SETTING_OUTPUT, PORT_AUTO_SOURCE_SETTING_PROCESS, Tunnel, TUNNEL_VIEW_CONTAINER_ID, TUNNEL_VIEW_ID, TunnelSource } from 'vs/workbench/services/remote/common/remoteExplorerService';
import { forwardedPortsViewEnabled, ForwardPortAction, OpenPortInBrowserAction, TunnelPanel, TunnelPanelDescriptor, TunnelViewModel, OpenPortInPreviewAction, openPreviewEnabledContext } from 'vs/workbench/contrib/remote/browser/tunnelView';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
Expand Down Expand Up @@ -621,24 +621,29 @@ class ProcAutomaticPortForwarding extends Disposable {

private async handleCandidateUpdate(removed: Map<string, { host: string; port: number }>) {
const removedPorts: number[] = [];
let autoForwarded: Set<string>;
let autoForwarded: Map<string, string | Tunnel>;
if (this.unforwardOnly) {
autoForwarded = new Set();
autoForwarded = new Map();
for (const entry of this.remoteExplorerService.tunnelModel.forwarded.entries()) {
if (entry[1].source.source === TunnelSource.Auto) {
autoForwarded.add(entry[0]);
autoForwarded.set(entry[0], entry[1]);
}
}
} else {
autoForwarded = this.autoForwarded;
autoForwarded = new Map(this.autoForwarded.entries());
}

for (const removedPort of removed) {
const key = removedPort[0];
const value = removedPort[1];
if (autoForwarded.has(key)) {
let value = removedPort[1];
const forwardedValue = mapHasAddressLocalhostOrAllInterfaces(autoForwarded, value.host, value.port);
if (forwardedValue) {
if (typeof forwardedValue === 'string') {
this.autoForwarded.delete(key);
} else {
value = { host: forwardedValue.remoteHost, port: forwardedValue.remotePort };
}
await this.remoteExplorerService.close(value);
autoForwarded.delete(key);
removedPorts.push(value.port);
} else if (this.notifiedOnly.has(key)) {
this.notifiedOnly.delete(key);
Expand Down

0 comments on commit 5886713

Please sign in to comment.