Skip to content

Commit c7195ce

Browse files
authored
cli: recycle tunnels more correctly (microsoft#188522)
Previously we only tried to recycle a tunnel once, so if the tunnel limit changed and was reduced by >1 we'd fail even though we should have actually just recycled multiple tunnels. Also, only trigger recycling if the specific tunnel limit is hit.
1 parent df58df8 commit c7195ce

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

cli/src/tunnels/dev_tunnels.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ use tunnels::management::{
3333

3434
use super::wsl_detect::is_wsl_installed;
3535

36+
static TUNNEL_COUNT_LIMIT_NAME: &str = "TunnelsPerUserPerLocation";
37+
3638
#[derive(Clone, Serialize, Deserialize)]
3739
pub struct PersistedTunnel {
3840
pub name: String,
@@ -458,8 +460,6 @@ impl DevTunnels {
458460

459461
self.check_is_name_free(name).await?;
460462

461-
let mut tried_recycle = false;
462-
463463
let new_tunnel = Tunnel {
464464
tags: vec![
465465
name.to_string(),
@@ -480,13 +480,14 @@ impl DevTunnels {
480480
Err(HttpError::ResponseError(e))
481481
if e.status_code == StatusCode::TOO_MANY_REQUESTS =>
482482
{
483-
if !tried_recycle && self.try_recycle_tunnel().await? {
484-
tried_recycle = true;
485-
continue;
486-
}
487-
488483
if let Some(d) = e.get_details() {
489484
let detail = d.detail.unwrap_or_else(|| "unknown".to_string());
485+
if detail.contains(TUNNEL_COUNT_LIMIT_NAME)
486+
&& self.try_recycle_tunnel().await?
487+
{
488+
continue;
489+
}
490+
490491
return Err(AnyError::from(TunnelCreationFailed(
491492
name.to_string(),
492493
detail,

0 commit comments

Comments
 (0)