Skip to content
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

cli: recycle all tunnels the cli creates for all scenarios #191800

Merged
merged 1 commit into from
Aug 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 8 additions & 5 deletions cli/src/tunnels/dev_tunnels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ impl ActiveTunnel {

const VSCODE_CLI_TUNNEL_TAG: &str = "vscode-server-launcher";
const VSCODE_CLI_FORWARDING_TAG: &str = "vscode-port-forward";
const OWNED_TUNNEL_TAGS: &[&str] = &[VSCODE_CLI_TUNNEL_TAG, VSCODE_CLI_FORWARDING_TAG];
const MAX_TUNNEL_NAME_LENGTH: usize = 20;

fn get_host_token_from_tunnel(tunnel: &Tunnel) -> String {
Expand Down Expand Up @@ -635,7 +636,7 @@ impl DevTunnels {
"Tunnel limit hit, trying to recycle an old tunnel"
);

let existing_tunnels = self.list_all_server_tunnels().await?;
let existing_tunnels = self.list_tunnels_with_tag(OWNED_TUNNEL_TAGS).await?;

let recyclable = existing_tunnels
.iter()
Expand Down Expand Up @@ -667,13 +668,15 @@ impl DevTunnels {
}
}

async fn list_all_server_tunnels(&mut self) -> Result<Vec<Tunnel>, AnyError> {
async fn list_tunnels_with_tag(
&mut self,
tags: &[&'static str],
) -> Result<Vec<Tunnel>, AnyError> {
let tunnels = spanf!(
self.log,
self.log.span("dev-tunnel.listall"),
self.client.list_all_tunnels(&TunnelRequestOptions {
tags: vec![self.tag.to_string()],
require_all_tags: true,
tags: tags.iter().map(|t| t.to_string()).collect(),
..Default::default()
})
)
Expand Down Expand Up @@ -711,7 +714,7 @@ impl DevTunnels {
preferred_name: Option<&str>,
mut use_random_name: bool,
) -> Result<String, AnyError> {
let existing_tunnels = self.list_all_server_tunnels().await?;
let existing_tunnels = self.list_tunnels_with_tag(&[self.tag]).await?;
let is_name_free = |n: &str| {
!existing_tunnels.iter().any(|v| {
v.status
Expand Down