Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: panic for programmer error, more diagnostics, remove duplicated map lookup #126

Merged
merged 5 commits into from
Sep 20, 2023
Merged
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
17 changes: 8 additions & 9 deletions crates/tarball/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,24 +128,23 @@ pub async fn download_tarball_to_store(
}
CacheValue::InProgress(notify) => Arc::clone(notify),
};

tracing::info!(target: "pacquet::download", ?package_url, "Wait for cache");
notify.notified().await;
if let Some(cached) = cache.get(package_url) {
if let CacheValue::Available(cas_paths) = &*cached.read().await {
return Ok(Arc::clone(cas_paths));
}
if let CacheValue::Available(cas_paths) = &*cache_lock.read().await {
return Ok(Arc::clone(cas_paths));
}
Err(TarballError::Io(std::io::Error::new(
std::io::ErrorKind::Other,
"Failed to get or compute tarball data",
)))
unreachable!("Failed to get or compute tarball data for {package_url:?}");
} else {
let notify = Arc::new(Notify::new());
let cache_lock = notify
.pipe_ref(Arc::clone)
.pipe(CacheValue::InProgress)
.pipe(RwLock::new)
.pipe(Arc::new);
cache.insert(package_url.to_string(), Arc::clone(&cache_lock));
if cache.insert(package_url.to_string(), Arc::clone(&cache_lock)).is_some() {
tracing::warn!(target: "pacquet::download", ?package_url, "Race condition detected when writing to cache");
KSXGitHub marked this conversation as resolved.
Show resolved Hide resolved
}
let cas_paths = download_tarball_to_store_uncached(
package_url,
http_client,
Expand Down