Cancel waiting tasks on resolution error (#753)

## Summary

I don't understand why this works (because I don't understand why it's
erroring) but it does. See:
https://github.com/astral-sh/puffin/pull/746#issuecomment-1875722454.

## Test Plan

```
cargo run --bin puffin pip-install requires-transitive-incompatible-with-transitive-8329cfc0 --extra-index-url https://test.pypi.org/simple -n
```
This commit is contained in:
Charlie Marsh 2024-01-03 16:18:27 -04:00 committed by GitHub
parent a8e52d2899
commit cfffcbb269
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 1 deletions

View file

@ -24,3 +24,15 @@ pub(crate) struct Index {
/// A map from source URL to precise URL.
pub(crate) redirects: OnceMap<Url, Url>,
}
impl Index {
/// Cancel all waiting tasks.
///
/// Warning: waiting on tasks that have been canceled will cause the index to hang.
pub(crate) fn cancel_all(&self) {
self.packages.cancel_all();
self.distributions.cancel_all();
self.incompatibilities.cancel_all();
self.redirects.cancel_all();
}
}

View file

@ -202,7 +202,11 @@ impl<'a, Provider: ResolverProvider> Resolver<'a, Provider> {
}
resolution = resolve_fut => {
resolution.map_err(|err| {
// Add version information to improve unsat error messages
// Ensure that any waiting tasks are cancelled prior to accessing any of the
// index entries.
self.index.cancel_all();
// Add version information to improve unsat error messages.
if let ResolveError::NoSolution(err) = err {
ResolveError::NoSolution(err.with_available_versions(&self.python_requirement, &self.index.packages).with_selector(self.selector.clone()))
} else {

View file

@ -71,6 +71,13 @@ impl<K: Eq + Hash, V> OnceMap<K, V> {
{
self.wait_map.get(key)
}
/// Cancel all waiting tasks.
///
/// Warning: waiting on tasks that have been canceled will cause the map to hang.
pub fn cancel_all(&self) {
self.wait_map.cancel_all();
}
}
impl<K: Eq + Hash + Clone, V> Default for OnceMap<K, V> {