-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide extension API to exclude ports from forwarding #115616
Comments
We currently have a setting that lets user configure "ignored" ports: "remote.portsAttributes": {
"35000-38000": {
"label": "My server",
"onAutoForward": "ignore",
}
} This setting also allows setting other properties of the port, such as the label. Proposal: export enum PortAutoForwardAction {
Notify,
OpenBrowser,
Silent,
Ignore
}
export interface PortAttributes {
port: number;
autoForwardAction: PortAutoForwardAction
}
export interface PortAttributesProvider {
providePortAttributes(port: number[], token: CancellationToken): ProviderResult<PortAttributes[]>;
}
export namespace workspace {
export function registerPortAttributesProvider(portRange: [number, number], provider: PortAttributesProvider): Disposable;
} |
I discussed with @weinand and there are several places unwanted ports can come from: a) Debugees. These are started by debugger extensions, and the debug internals of VS Code know nothing about them. Cases (a) and (b) above are the most common cases that we want to solve for. We discussed excluding all processes that come from the extension host from auto forwarded, but that does not solve case (a). @connor4312 since JS debug would be the first client of any API I'd love to get your input here. The above |
The API seems generally sensible to me. While a consumer could pass it as Particularly in this case, providers will often get called with ports they know nothing about. It looks like |
@connor4312 you said
When does your DA or extension know what the free port is? and you said:
The return type of |
Yea, that's correct. I would need to wait a few moments so that any port resolutions can happen. Or if this becomes problematic I could restrict it to a specific port range, then manually choose a free port and only have the waiting logic for ports in that range
Yep |
That should still be ok then. Even if you have to wait a few moments, you already know that you need to wait a few moments. So if the call comes from VS Code to your extension asking your extension to provide port information, you can wait the time you need to know the port number before returning the port information. |
New proposal: export interface ProcessInformation {
isUserFacing: boolean;
}
export interface ProcessInformationProvider {
provideProcessInformation(process: { pid: number, port: number }, token: CancellationToken): ProviderResult<ProcessInformation>;
}
export namespace workspace {
export function registerProcessInformationProvider(selector: { portRange?: [number, number], processRange?: [number, number] }, processInformationProvider: ProcessInformationProvider): Disposable;
} |
@connor4312 the API includes the pid, and I imagine that you'll know the pid almost immediately. Is that correct? |
In the auto attach / debug terminal case, not any earlier than I will the port: the debugee still needs to connect back to the extension and tell us it exists before we'll know its port. But for less esoteric cases passing the pid is good, I'm sure other consumers will appreciate that. API looks good now. I'm not sure how useful the process range is -- as far as I know all OSes assign process IDs with an increment counter, so an extension would not know the process ID of whatever they're interested in ahead of time. |
@connor4312 since this API is very specific, I'm now trying to find a way to avoid adding API. You mentioned above using a port range instead of 0. How averse to this are you? If you use a range, then you could use the configuration API to simply add to
If you set that before starting your debugee, then I will get the setting changed event first and know to ignore your range. What do you think of this? |
I think using a provider in combination with a ports range is ideal, in order to avoid accidentally excluding user programs. Then the delay in that case would be less problematic: in the high likelihood that the queried port is actually a debugged program, it's not going to be shown to the user anyway. |
My (and @jrieken's) concern is that this a lot of API to add to support a very narrow scenario: don't auto forward debugee's debug ports. This API doesn't support any other scenario. Would you be willing to try the settings approach? |
Yes, the concern is that port forwarding, by its nature, forwards many unwanted ports. Ports from processes I am not interested in, ports that don't speak http, ports I cannot connect to etc. The screen shot below is what I see when I connect to my raspberry pi which run jupyter-lab. There are 7 ports forwarded (prominently announced via the status bar and notification) and I am only interested in one of them (iff at all) I know that debugging ports contribute to this problem but they are only a small part of this overall problem. So, an API should tackle (or enable tackling) the whole problem not just a selected portion. |
Proposal as of the time of this comment: export enum PortAutoForwardAction {
Notify,
OpenBrowser,
Silent,
Ignore
}
export interface PortAttributes {
port: number;
autoForwardAction: PortAutoForwardAction
}
export interface PortAttributesProvider {
providePortAttributes(port: number, pid: number, token: CancellationToken): ProviderResult<PortAttributes>;
}
export namespace workspace {
export function registerPortAttributesProvider(portRange: [number, number], provider: PortAttributesProvider): Disposable;
} |
I can give the config approach a shot. Could scope to say 100 ports somewhere random, and try to preferentially choose those when starting to debug. |
@connor4312 I have merged the first pass at this API. My hope is that it is pretty easy to use, so even if it changes a lot as we continue to review it, you won't lose a lot of work by adopting it now. vscode/src/vs/vscode.proposed.d.ts Lines 2851 to 2880 in 0604478
You'll need to implement a If you have time to register your provider after you know the pids you care about, then you can include the Internally, I batch ports that have the same pid, so you should see almost no delay between calls if your ports are all in the same process. I'm thinking of adding a regex "commandLine" to the |
* Update port attributes arguments to be a property bag Part of #115616 * Gracefully handle API breakage
Let's bring this back into the plan once microsoft/vscode-python#21292 is complete. |
From @weinand:
Today the tunneling service blindly forwards all communication ports.
This includes ports that are used for debugging (even if our remote debugging feature does not need these ports to be forwarded).
This is confusing for users because they see ports that they are not really interested in.
I propose to add extension API so that individual ports or port ranges can be excluded from forwarding.
Debug extensions could use this API.
The text was updated successfully, but these errors were encountered: