From 98bd86cb7583f60ce207b296e554b252403eafa7 Mon Sep 17 00:00:00 2001 From: Tatsuya Kawano Date: Wed, 4 Oct 2023 09:01:30 +0800 Subject: [PATCH] Update dependency moka to v0.12.1 --- Cargo.lock | 116 ++------------------------- Cargo.toml | 2 +- src/controllers/version/downloads.rs | 18 +++-- 3 files changed, 20 insertions(+), 116 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9601eeabb83..33ca0d5f8f7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -156,26 +156,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "async-io" -version = "1.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fc5b45d93ef0529756f812ca52e44c221b35341892d3dcc34132ac02f3dd2af" -dependencies = [ - "async-lock", - "autocfg", - "cfg-if", - "concurrent-queue", - "futures-lite", - "log", - "parking", - "polling", - "rustix 0.37.24", - "slab", - "socket2 0.4.9", - "waker-fn", -] - [[package]] name = "async-lock" version = "2.8.0" @@ -613,15 +593,6 @@ dependencies = [ "unicode_categories", ] -[[package]] -name = "concurrent-queue" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f057a694a54f12365049b0958a1685bb52d567f5593b355fbf685838e873d400" -dependencies = [ - "crossbeam-utils", -] - [[package]] name = "console" version = "0.15.7" @@ -1390,21 +1361,6 @@ version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964" -[[package]] -name = "futures-lite" -version = "1.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49a9d51ce47660b1e808d3c990b4709f2f415d928835a17dfd16991515c46bce" -dependencies = [ - "fastrand 1.9.0", - "futures-core", - "futures-io", - "memchr", - "parking", - "pin-project-lite", - "waker-fn", -] - [[package]] name = "futures-macro" version = "0.3.28" @@ -1855,17 +1811,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "io-lifetimes" -version = "1.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2" -dependencies = [ - "hermit-abi", - "libc", - "windows-sys 0.48.0", -] - [[package]] name = "ipnet" version = "2.8.0" @@ -2001,12 +1946,6 @@ version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" -[[package]] -name = "linux-raw-sys" -version = "0.3.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" - [[package]] name = "linux-raw-sys" version = "0.4.10" @@ -2174,12 +2113,12 @@ dependencies = [ [[package]] name = "moka" -version = "0.11.3" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa6e72583bf6830c956235bff0d5afec8cf2952f579ebad18ae7821a917d950f" +checksum = "d8017ec3548ffe7d4cef7ac0e12b044c01164a74c0f3119420faeaf13490ad8b" dependencies = [ - "async-io", "async-lock", + "async-trait", "crossbeam-channel", "crossbeam-epoch", "crossbeam-utils", @@ -2188,7 +2127,6 @@ dependencies = [ "parking_lot", "quanta", "rustc_version", - "scheduled-thread-pool", "skeptic", "smallvec", "tagptr", @@ -2436,12 +2374,6 @@ dependencies = [ "sha2", ] -[[package]] -name = "parking" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e52c774a4c39359c1d1c52e43f73dd91a75a614652c825408eec30c95a9b2067" - [[package]] name = "parking_lot" version = "0.12.1" @@ -2617,22 +2549,6 @@ version = "0.3.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" -[[package]] -name = "polling" -version = "2.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b2d323e8ca7996b3e23126511a523f7e62924d93ecd5ae73b333815b0eb3dce" -dependencies = [ - "autocfg", - "bitflags 1.3.2", - "cfg-if", - "concurrent-queue", - "libc", - "log", - "pin-project-lite", - "windows-sys 0.48.0", -] - [[package]] name = "polyval" version = "0.6.1" @@ -2974,20 +2890,6 @@ dependencies = [ "semver", ] -[[package]] -name = "rustix" -version = "0.37.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4279d76516df406a8bd37e7dff53fd37d1a093f997a3c34a5c21658c126db06d" -dependencies = [ - "bitflags 1.3.2", - "errno", - "io-lifetimes", - "libc", - "linux-raw-sys 0.3.8", - "windows-sys 0.48.0", -] - [[package]] name = "rustix" version = "0.38.17" @@ -2997,7 +2899,7 @@ dependencies = [ "bitflags 2.4.0", "errno", "libc", - "linux-raw-sys 0.4.10", + "linux-raw-sys", "windows-sys 0.48.0", ] @@ -3615,7 +3517,7 @@ dependencies = [ "cfg-if", "fastrand 2.0.1", "redox_syscall", - "rustix 0.38.17", + "rustix", "windows-sys 0.48.0", ] @@ -3636,7 +3538,7 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "21bebf2b7c9e0a515f6e0f8c51dc0f8e4696391e6f1ff30379559f8365fb0df7" dependencies = [ - "rustix 0.38.17", + "rustix", "windows-sys 0.48.0", ] @@ -4149,12 +4051,6 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c3082ca00d5a5ef149bb8b555a72ae84c9c59f7250f013ac822ac2e49b19c64" -[[package]] -name = "waker-fn" -version = "1.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3c4517f54858c779bbcbf228f4fca63d121bf85fbecb2dc578cdf4a39395690" - [[package]] name = "walkdir" version = "2.4.0" diff --git a/Cargo.toml b/Cargo.toml index 8af4e636756..7c4969308d0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -66,7 +66,7 @@ ipnetwork = "=0.20.0" tikv-jemallocator = { version = "=0.5.4", features = ['unprefixed_malloc_on_supported_platforms', 'profiling'] } lettre = { version = "=0.10.4", default-features = false, features = ["file-transport", "smtp-transport", "native-tls", "hostname", "builder"] } minijinja = "=1.0.8" -moka = { version = "=0.11.3", features = ["future"] } +moka = { version = "=0.12.1", features = ["future"] } oauth2 = { version = "=4.4.2", default-features = false, features = ["reqwest"] } object_store = { version = "=0.7.1", features = ["aws"] } once_cell = "=1.18.0" diff --git a/src/controllers/version/downloads.rs b/src/controllers/version/downloads.rs index 925b575c631..78450fb4b0a 100644 --- a/src/controllers/version/downloads.rs +++ b/src/controllers/version/downloads.rs @@ -10,6 +10,7 @@ use crate::models::{Crate, VersionDownload}; use crate::schema::*; use crate::views::EncodableVersionDownload; use chrono::{Duration, NaiveDate, Utc}; +use tracing::Instrument; /// Handles the `GET /crates/:crate_id/:version/download` route. /// This returns a URL to the location where the crate is stored. @@ -22,8 +23,11 @@ pub async fn download( let cache_key = (crate_name.to_string(), version.to_string()); - let cache_result = - info_span!("cache.read", ?cache_key).in_scope(|| app.version_id_cacher.get(&cache_key)); + let cache_result = app + .version_id_cacher + .get(&cache_key) + .instrument(info_span!("cache.read", ?cache_key)) + .await; let (crate_name, version) = if let Some(version_id) = cache_result { app.instance_metrics.version_id_cache_hits.inc(); @@ -37,6 +41,7 @@ pub async fn download( app.instance_metrics.version_id_cache_misses.inc(); let app = app.clone(); + let rt = tokio::runtime::Handle::current(); conduit_compat(move || { // When no database connection is ready unconditional redirects will be performed. This could // happen if the pool is not healthy or if an operator manually configured the application to @@ -89,9 +94,12 @@ pub async fn download( // Non-canonical requests fallback to the "slow" path with a DB query, but // we typically only get a few hundred non-canonical requests in a day anyway. info_span!("cache.write", ?cache_key).in_scope(|| { - app.version_id_cacher - .blocking() - .insert(cache_key, version_id) + // SAFETY: This block_on should not panic. block_on will panic if the + // current thread is an executor thread of a Tokio runtime. (Will panic + // by "Cannot start a runtime from within a runtime"). Here, we are in + // a spawn_blocking call because of conduit_compat, so our current thread + // is not an executor of the runtime. + rt.block_on(app.version_id_cacher.insert(cache_key, version_id)) }); Ok((crate_name, version))