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

cargo generate-lockfile panicked when --offline #13656

Closed
weihanglo opened this issue Mar 26, 2024 · 0 comments · Fixed by #13657
Closed

cargo generate-lockfile panicked when --offline #13656

weihanglo opened this issue Mar 26, 2024 · 0 comments · Fixed by #13657
Labels
A-offline Area: offline mode C-bug Category: bug Command-generate-lockfile regression-from-stable-to-nightly Regression in nightly that previously worked in stable. S-triage Status: This issue is waiting on initial triage.

Comments

@weihanglo
Copy link
Member

Problem

Got a panic when generating lockfile:

thread 'main' panicked at src/cargo/sources/registry/download.rs:166:21:
package cache lock is not currently held, Cargo forgot to call `acquire_package_cache_lock` before we got to this stack frame

Backtrace

stack backtrace:
   0: _rust_begin_unwind
   1: core::panicking::panic_fmt
   2: <cargo::util::context::GlobalContext>::assert_package_cache_locked
   3: cargo::sources::registry::download::is_crate_downloaded
   4: <hashbrown::raw::RawIterRange<(semver::Version, cargo::sources::registry::index::MaybeIndexSummary)>>::fold_impl::<<hashbrown::map::IterMut<semver::Version, cargo::sources::registry::index::MaybeIndexSummary> as core::iter::traits::iterator::Iterator>::fold<(), core::iter::adapters::filter_map::filter_map_fold<(&semver::Version, &mut cargo::sources::registry::index::MaybeIndexSummary), &mut cargo::sources::registry::index::MaybeIndexSummary, (), <cargo::sources::registry::index::RegistryIndex>::summaries::{closure#0}, core::iter::adapters::filter_map::filter_map_fold<&mut cargo::sources::registry::index::MaybeIndexSummary, &cargo::sources::registry::index::IndexSummary, (), <cargo::sources::registry::index::RegistryIndex>::summaries::{closure#1}, core::iter::adapters::map::map_fold<&cargo::sources::registry::index::IndexSummary, cargo::sources::registry::index::IndexSummary, (), <cargo::sources::registry::index::RegistryIndex>::query_inner_with_online::{closure#0}, core::iter::traits::iterator::Iterator::for_each::call<cargo::sources::registry::index::IndexSummary, &mut dyn core::ops::function::FnMut<(cargo::sources::registry::index::IndexSummary,), Output = ()>>::{closure#0}>::{closure#0}>::{closure#0}>::{closure#0}>::{closure#0}, ()>
   5: <cargo::sources::registry::index::RegistryIndex>::query_inner
   6: <cargo::sources::registry::RegistrySource as cargo::sources::source::Source>::query
   7: <cargo::sources::replaced::ReplacedSource as cargo::sources::source::Source>::query
   8: <cargo::core::registry::PackageRegistry as cargo::core::registry::Registry>::query
   9: <cargo::core::registry::PackageRegistry as cargo::core::registry::Registry>::query_vec
  10: cargo::ops::cargo_generate_lockfile::print_lockfile_changes
  11: cargo::ops::cargo_generate_lockfile::generate_lockfile
  12: cargo::commands::generate_lockfile::exec
  13: <cargo::cli::Exec>::exec
  14: cargo::cli::main
  15: cargo::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace

This was introduced in #13561

Steps

cargo new foo
cd foo
cargo add empty-library
cargo +nightly generate-lockfile --offline

Possible Solution(s)

Hold the lock before querying registry even when --offline, since offline query still checks downloaded .crate tarball while querying:

// First filter summaries for `--offline`. If we're online then
// everything is a candidate, otherwise if we're offline we're only
// going to consider candidates which are actually present on disk.
//
// Note: This particular logic can cause problems with
// optional dependencies when offline. If at least 1 version
// of an optional dependency is downloaded, but that version
// does not satisfy the requirements, then resolution will
// fail. Unfortunately, whether or not something is optional
// is not known here.
.map(|s| {
if online || load.is_crate_downloaded(s.package_id()) {
s.clone()
} else {
IndexSummary::Offline(s.as_summary().clone())
}
})

Notes

No response

Version

cargo 1.79.0-nightly (a510712d0 2024-03-25)
release: 1.79.0-nightly
commit-hash: a510712d05c6c98f987af24dd73cdfafee8922e6
commit-date: 2024-03-25
@weihanglo weihanglo added C-bug Category: bug Command-generate-lockfile regression-from-stable-to-nightly Regression in nightly that previously worked in stable. A-offline Area: offline mode S-triage Status: This issue is waiting on initial triage. labels Mar 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-offline Area: offline mode C-bug Category: bug Command-generate-lockfile regression-from-stable-to-nightly Regression in nightly that previously worked in stable. S-triage Status: This issue is waiting on initial triage.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant