Avoid panicking when the resolver thread encounters a closed channel (#6182)

Closes https://github.com/astral-sh/uv/issues/6167

We've been seeing intermittent failures in CI, which we thought were
unexpected HTTP 401s but it actually looks like a panic when handling an
expected HTTP error. I believe the problem is that an early client error
can cause the channel to close and we crash when we unwrap the `send`.
This commit is contained in:
Zanie Blue 2024-08-18 16:04:05 -05:00 committed by GitHub
parent 615dda0e94
commit baf17bee86
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -271,7 +271,9 @@ impl<Provider: ResolverProvider, InstalledPackages: InstalledPackagesProvider>
.name("uv-resolver".into())
.spawn(move || {
let result = solver.solve(index_locations, request_sink);
tx.send(result).unwrap();
// This may fail if the main thread returned early due to an error.
let _ = tx.send(result);
})
.unwrap();
@ -279,6 +281,7 @@ impl<Provider: ResolverProvider, InstalledPackages: InstalledPackagesProvider>
// Wait for both to complete.
let ((), resolution) = tokio::try_join!(requests_fut, resolve_fut)?;
state.on_complete();
resolution
}