Close all unused ports command#244245
Conversation
|
You can test it with the test resolver:
|
| id: RemoteTunnelCommandIds.closeUnusedPorts, | ||
| title: RemoteTunnelCommandLabels.closeUnusedPorts, | ||
| category: REMOTE_TUNNEL_CATEGORY, | ||
| menu: [] |
There was a problem hiding this comment.
When the remote system is NOT linux or if remote.autoForwardPortsSource is set to output, then none of the ports have a running process.
When the remote system is linux and the setting remote.autoForwardPortsSource is not set to output, I think this command makes sense. I would add the command to the command palette in this case.
Thank you for this pointer @alexr00! Am I expected to add anything to |
|
Hmm, that should be it. You should just be able to copy the |
|
Hmm, no that isn't working out for me. |
|
Hi @alexr00, any thoughts here? |
|
Hello @alexr00, I was able to get this working locally: I needed to add "tunnelApplicationConfig": {
"authenticationProviders": {
"github": {
"scopes": [
"repo",
"user:email"
]
}
},
"editorWebUrl": "https://vscode.dev",
"extension": {
"extensionId": "ms-vscode.remote-server",
"friendlyName": "Remote Server"
}
},to Any thoughts on how I can test the conditions part? |
There was a problem hiding this comment.
Thanks for the PR! Sorry about the bad instructions for testing locally, I thought you were working on a command for all remotes, not just for the Remote Tunnels.
I actually think a "close all ports which don't have a running process" is a useful command for any remote, not just remote tunnels. Would you be willing to see if you could move the action into https://github.com/nojaf/vscode/blob/main/src/vs/workbench/contrib/remote/electron-sandbox/remote.contribution.ts ?
Then, in your command precondition you would also need to check if the remote is Windows, as Windows remotes will never show as having an associated process.
97ea615 to
538f756
Compare
|
Hi @alexr00, thank you for the feedback! |
| menu: [{ | ||
| id: MenuId.CommandPalette | ||
| }], | ||
| precondition: ContextKeyExpr.and(ContextKeyExpr.notEquals(`config.${PORT_AUTO_SOURCE_SETTING}`, PORT_AUTO_SOURCE_SETTING_OUTPUT), RemoteNameContext) |
There was a problem hiding this comment.
The contexts you were using @nojaf weren't using the OS of the remote, they were using the local OS. I've looked around but we don't seem to already have broadly useful remote OS context. I removed them, and added a context for whether we're connected to a remote.
I've inlined your strings and also used constants where we have them.
There was a problem hiding this comment.
Thanks for these changes!
alexr00
left a comment
There was a problem hiding this comment.
Thanks for making the changes! I made a few of my own, and I have one question.
| // collect all forwarded ports and filter out those who do not have a process running | ||
| const forwarded = remoteExplorerService.tunnelModel.forwarded; | ||
| for (const [_, tunnel] of forwarded) { | ||
| if (!tunnel.hasRunningProcess) { |
There was a problem hiding this comment.
I think if you check tunnel.hasRunningProcess === false here instead of checking for undefined then you'll only close tunnels for which we don't have a running process, not simple ones which we don't know about (like on Windows). Can you try it out and see if that's the case?
There was a problem hiding this comment.
That makes sense. It still worked for me after changing this.

Hello,
When connecting to a remote dev container, we often encounter the issue where forwarded ports remain open even after the remote process has stopped running. This occurs due to our setup, and VSCode cannot always detect when this happens.
We would like to propose adding a command that automatically clears all forwarded ports without an active process.
Would this feature be accepted?
If so, how can I test this locally? I attempted to install a local VSIX of the remote container extension, but I'm unable to start a dev container. I believe this issue may stem from proprietary boundaries. I’m open to any suggestions on how to test this in another way.