Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion crates/uv/src/commands/auth/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ use crate::commands::ExitStatus;
use crate::printer::Printer;
use crate::settings::NetworkSettings;

// We retry no more than this many times when polling for login status.
const STATUS_RETRY_LIMIT: u32 = 60;

/// Login to a service.
pub(crate) async fn login(
service: Service,
Expand Down Expand Up @@ -215,6 +218,7 @@ pub(crate) async fn pyx_login_with_browser(
url
};

let mut retry = 0;
let credentials = loop {
let response = client
.for_host(store.api())
Expand All @@ -224,7 +228,8 @@ pub(crate) async fn pyx_login_with_browser(
match response.status() {
// Retry on 404.
reqwest::StatusCode::NOT_FOUND => {
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
tokio::time::sleep(std::time::Duration::from_secs(3)).await;
retry += 1;
}
// Parse the credentials on success.
_ if response.status().is_success() => {
Expand All @@ -236,6 +241,10 @@ pub(crate) async fn pyx_login_with_browser(
break Err(anyhow::anyhow!("Failed to login with code `{status}`"));
}
}

if retry >= STATUS_RETRY_LIMIT {
break Err(anyhow::anyhow!("Login session timed out"));
}
}?;

store.write(&credentials).await?;
Expand Down
Loading