Skip to content

Commit c6d0b41

Browse files
authored
Limit uv auth login pyx.dev retries to 60s (#16498)
## Summary Without this, a user who does `uv auth login ...` will retry against the service's status endpoint forever. This probably isn't what they intended (they probably walked away from their machine), so we end their login initiation session after 60 retries. Since we do a retry every second, this gives them no less than a minute to complete a login (which should be more than enough). ## Test Plan We don't have browser-negotiated login tests at the moment in CI, but I've tested this locally: ```console % ./target/debug/uv auth login pyx.dev Logging in with https://api.pyx.dev/auth/cli/login/REDACTED error: Login session timed out ``` (That took well over a minute, so 60s is a lower bound assuming a very optimal network roundtrip on each poll.) --------- Signed-off-by: William Woodruff <[email protected]>
1 parent 2d54f32 commit c6d0b41

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

crates/uv/src/commands/auth/login.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ use crate::commands::ExitStatus;
1919
use crate::printer::Printer;
2020
use crate::settings::NetworkSettings;
2121

22+
// We retry no more than this many times when polling for login status.
23+
const STATUS_RETRY_LIMIT: u32 = 60;
24+
2225
/// Login to a service.
2326
pub(crate) async fn login(
2427
service: Service,
@@ -215,6 +218,7 @@ pub(crate) async fn pyx_login_with_browser(
215218
url
216219
};
217220

221+
let mut retry = 0;
218222
let credentials = loop {
219223
let response = client
220224
.for_host(store.api())
@@ -225,6 +229,7 @@ pub(crate) async fn pyx_login_with_browser(
225229
// Retry on 404.
226230
reqwest::StatusCode::NOT_FOUND => {
227231
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
232+
retry += 1;
228233
}
229234
// Parse the credentials on success.
230235
_ if response.status().is_success() => {
@@ -236,6 +241,12 @@ pub(crate) async fn pyx_login_with_browser(
236241
break Err(anyhow::anyhow!("Failed to login with code `{status}`"));
237242
}
238243
}
244+
245+
if retry >= STATUS_RETRY_LIMIT {
246+
break Err(anyhow::anyhow!(
247+
"Login session timed out after {STATUS_RETRY_LIMIT} seconds"
248+
));
249+
}
239250
}?;
240251

241252
store.write(&credentials).await?;

0 commit comments

Comments
 (0)