Skip to content

Commit

Permalink
Avoid panicking when the resolver thread encounters a closed channel
Browse files Browse the repository at this point in the history
  • Loading branch information
zanieb committed Aug 18, 2024
1 parent 0091adf commit e15f280
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions crates/uv-resolver/src/resolver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,18 +267,25 @@ impl<Provider: ResolverProvider, InstalledPackages: InstalledPackagesProvider>
let solver = state.clone();
let index_locations = provider.index_locations().clone();
let (tx, rx) = oneshot::channel();
thread::Builder::new()
let handle = thread::Builder::new()
.name("uv-resolver".into())
.spawn(move || {
let result = solver.solve(index_locations, request_sink);
tx.send(result).unwrap();
tx.send(result)
})
.unwrap();

let resolve_fut = async move { rx.await.map_err(|_| ResolveError::ChannelClosed) };

// Wait for both to complete.
let ((), resolution) = tokio::try_join!(requests_fut, resolve_fut)?;

// Retrieve a possible send error from the solver thread
handle
.join()
.unwrap()
.map_err(|_| ResolveError::ChannelClosed)?;

state.on_complete();
resolution
}
Expand Down

0 comments on commit e15f280

Please sign in to comment.