From b0306c9ec7f04d1924f7a055ee2853802a94b210 Mon Sep 17 00:00:00 2001 From: monosans Date: Wed, 1 Oct 2025 09:24:55 +0300 Subject: [PATCH] fix: add more tokio::task::spawn_blocking --- src/config.rs | 4 ++-- src/fs.rs | 4 ++-- src/http.rs | 16 ++++++++++------ src/ipdb.rs | 5 ++--- src/main.rs | 2 +- 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/config.rs b/src/config.rs index a63681f..796c116 100644 --- a/src/config.rs +++ b/src/config.rs @@ -69,9 +69,9 @@ async fn get_output_path( raw_config: &raw_config::RawConfig, ) -> crate::Result { let output_path = if is_docker().await { - let mut path = dirs::data_local_dir() + let mut path = tokio::task::spawn_blocking(dirs::data_local_dir) + .await? .ok_or_eyre("failed to get user's local data directory")?; - #[expect(clippy::pathbuf_init_then_push)] path.push(APP_DIRECTORY_NAME); path } else { diff --git a/src/fs.rs b/src/fs.rs index 881927d..7271072 100644 --- a/src/fs.rs +++ b/src/fs.rs @@ -10,9 +10,9 @@ pub async fn get_cache_path() -> crate::Result { Ok(CACHE .get_or_try_init(async || -> crate::Result { - let mut path = dirs::cache_dir() + let mut path = tokio::task::spawn_blocking(dirs::cache_dir) + .await? .ok_or_eyre("failed to get user's cache directory")?; - #[expect(clippy::pathbuf_init_then_push)] path.push(APP_DIRECTORY_NAME); tokio::fs::create_dir_all(&path).await.wrap_err_with(|| { format!("failed to create directory: {}", path.display()) diff --git a/src/http.rs b/src/http.rs index 63ab243..11be751 100644 --- a/src/http.rs +++ b/src/http.rs @@ -29,18 +29,22 @@ pub struct BasicAuth { pub struct HickoryDnsResolver(Arc); impl HickoryDnsResolver { - pub fn new() -> Self { - let mut builder = hickory_resolver::TokioResolver::builder_tokio() - .unwrap_or_else(|_| { - hickory_resolver::TokioResolver::builder_with_config( + pub async fn new() -> Result { + let mut builder = tokio::task::spawn_blocking( + hickory_resolver::TokioResolver::builder_tokio, + ) + .await? + .unwrap_or_else(|_| { + hickory_resolver::TokioResolver::builder_with_config( hickory_resolver::config::ResolverConfig::cloudflare(), hickory_resolver::name_server::TokioConnectionProvider::default( ), ) - }); + }); + builder.options_mut().ip_strategy = hickory_resolver::config::LookupIpStrategy::Ipv4AndIpv6; - Self(Arc::new(builder.build())) + Ok(Self(Arc::new(builder.build()))) } } diff --git a/src/ipdb.rs b/src/ipdb.rs index cdb17b5..5de6e84 100644 --- a/src/ipdb.rs +++ b/src/ipdb.rs @@ -182,10 +182,9 @@ impl DbType { self, ) -> crate::Result> { let path = self.db_path().await?; - let name = self.name(); tokio::task::spawn_blocking(move || { - maxminddb::Reader::open_mmap(path).wrap_err_with(move || { - format!("failed to open IP database: {name}") + maxminddb::Reader::open_mmap(&path).wrap_err_with(move || { + format!("failed to open IP database: {}", path.display()) }) }) .await? diff --git a/src/main.rs b/src/main.rs index ddffd3f..031668e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -171,7 +171,7 @@ async fn main_task( event::Event, >, ) -> crate::Result<()> { - let dns_resolver = Arc::new(http::HickoryDnsResolver::new()); + let dns_resolver = Arc::new(http::HickoryDnsResolver::new().await?); let http_client = http::create_reqwest_client(&config, Arc::clone(&dns_resolver))?;