Skip to content

Commit 8813aca

Browse files
authored
cli: recycle all tunnels the cli creates for all scenarios (microsoft#191800)
Fixes microsoft#191749
1 parent d46d86d commit 8813aca

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

cli/src/tunnels/dev_tunnels.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ impl ActiveTunnel {
212212

213213
const VSCODE_CLI_TUNNEL_TAG: &str = "vscode-server-launcher";
214214
const VSCODE_CLI_FORWARDING_TAG: &str = "vscode-port-forward";
215+
const OWNED_TUNNEL_TAGS: &[&str] = &[VSCODE_CLI_TUNNEL_TAG, VSCODE_CLI_FORWARDING_TAG];
215216
const MAX_TUNNEL_NAME_LENGTH: usize = 20;
216217

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

638-
let existing_tunnels = self.list_all_server_tunnels().await?;
639+
let existing_tunnels = self.list_tunnels_with_tag(OWNED_TUNNEL_TAGS).await?;
639640

640641
let recyclable = existing_tunnels
641642
.iter()
@@ -667,13 +668,15 @@ impl DevTunnels {
667668
}
668669
}
669670

670-
async fn list_all_server_tunnels(&mut self) -> Result<Vec<Tunnel>, AnyError> {
671+
async fn list_tunnels_with_tag(
672+
&mut self,
673+
tags: &[&'static str],
674+
) -> Result<Vec<Tunnel>, AnyError> {
671675
let tunnels = spanf!(
672676
self.log,
673677
self.log.span("dev-tunnel.listall"),
674678
self.client.list_all_tunnels(&TunnelRequestOptions {
675-
tags: vec![self.tag.to_string()],
676-
require_all_tags: true,
679+
tags: tags.iter().map(|t| t.to_string()).collect(),
677680
..Default::default()
678681
})
679682
)
@@ -711,7 +714,7 @@ impl DevTunnels {
711714
preferred_name: Option<&str>,
712715
mut use_random_name: bool,
713716
) -> Result<String, AnyError> {
714-
let existing_tunnels = self.list_all_server_tunnels().await?;
717+
let existing_tunnels = self.list_tunnels_with_tag(&[self.tag]).await?;
715718
let is_name_free = |n: &str| {
716719
!existing_tunnels.iter().any(|v| {
717720
v.status

0 commit comments

Comments
 (0)