Bump rand crate to 0.9 (#12674)

This commit is contained in:
Folke Behrens
2025-07-22 11:31:39 +02:00
committed by GitHub
parent 5464552020
commit 9c0efba91e
60 changed files with 231 additions and 237 deletions

View File

@@ -8,7 +8,7 @@ use ed25519_dalek::SigningKey;
use hyper_util::rt::{TokioExecutor, TokioIo, TokioTimer};
use jose_jwk::jose_b64;
use postgres_client::config::SslMode;
use rand::rngs::OsRng;
use rand_core::OsRng;
use rustls::pki_types::{DnsName, ServerName};
use tokio::net::{TcpStream, lookup_host};
use tokio_rustls::TlsConnector;

View File

@@ -6,7 +6,7 @@ use std::time::Duration;
use indexmap::IndexMap;
use parking_lot::Mutex;
use rand::{Rng, thread_rng};
use rand::distr::uniform::{UniformSampler, UniformUsize};
use rustc_hash::FxHasher;
use tokio::time::Instant;
use tokio_util::sync::CancellationToken;
@@ -39,8 +39,9 @@ impl CancelSet {
}
pub(crate) fn take(&self) -> Option<CancellationToken> {
let dist = UniformUsize::new_inclusive(0, usize::MAX).expect("valid bounds");
for _ in 0..4 {
if let Some(token) = self.take_raw(thread_rng().r#gen()) {
if let Some(token) = self.take_raw(dist.sample(&mut rand::rng())) {
return Some(token);
}
tracing::trace!("failed to get cancel token");
@@ -48,7 +49,7 @@ impl CancelSet {
None
}
pub(crate) fn take_raw(&self, rng: usize) -> Option<CancellationToken> {
fn take_raw(&self, rng: usize) -> Option<CancellationToken> {
NonZeroUsize::new(self.shards.len())
.and_then(|len| self.shards[rng % len].lock().take(rng / len))
}

View File

@@ -428,7 +428,7 @@ where
loop {
interval.tick().await;
let shard = rng.gen_range(0..self.global_pool.shards().len());
let shard = rng.random_range(0..self.global_pool.shards().len());
self.gc(shard);
}
}

View File

@@ -77,7 +77,7 @@ pub async fn task_main(
{
let conn_pool = Arc::clone(&conn_pool);
tokio::spawn(async move {
conn_pool.gc_worker(StdRng::from_entropy()).await;
conn_pool.gc_worker(StdRng::from_os_rng()).await;
});
}
@@ -97,7 +97,7 @@ pub async fn task_main(
{
let http_conn_pool = Arc::clone(&http_conn_pool);
tokio::spawn(async move {
http_conn_pool.gc_worker(StdRng::from_entropy()).await;
http_conn_pool.gc_worker(StdRng::from_os_rng()).await;
});
}