Skip to content
Closed
Changes from all commits
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
4 changes: 4 additions & 0 deletions crates/pm/src/service/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,10 @@ async fn handle_cypress(
}

pub async fn update_package_binary(dir: &Path, name: &str) -> Result<()> {
if should_skip_binary_mirror() {
return Ok(());
}
Comment on lines +236 to +238
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Using should_skip_binary_mirror() here can lead to a race condition. Because it uses std::sync::OnceLock, it might cache a stale value if called before the async registry initialization is complete. This could cause it to incorrectly attempt a binary mirror lookup against the official npm registry.

To fix this, I suggest performing the check directly here. This avoids the caching issue, and the performance impact should be minimal. I've also preserved the debug logging from the original function.

A more comprehensive fix would be to make should_skip_binary_mirror async and use tokio::sync::OnceCell, which would solve this for all call sites.

Suggested change
if should_skip_binary_mirror() {
return Ok(());
}
let registry = get_registry();
if is_npm_registry(&registry) {
tracing::debug!("Skipping binary mirror update for npm registry: {}", registry);
return Ok(());
}


let config = load_config().await?;

let mirrors = config["mirrors"]["china"]
Expand Down
Loading