fix: add more tokio::task::spawn_blocking

This commit is contained in:
monosans
2025-10-01 09:24:55 +03:00
parent 55095173f2
commit b0306c9ec7
5 changed files with 17 additions and 14 deletions
+2 -2
View File
@@ -69,9 +69,9 @@ async fn get_output_path(
raw_config: &raw_config::RawConfig,
) -> crate::Result<PathBuf> {
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 {
+2 -2
View File
@@ -10,9 +10,9 @@ pub async fn get_cache_path() -> crate::Result<PathBuf> {
Ok(CACHE
.get_or_try_init(async || -> crate::Result<PathBuf> {
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())
+10 -6
View File
@@ -29,18 +29,22 @@ pub struct BasicAuth {
pub struct HickoryDnsResolver(Arc<hickory_resolver::TokioResolver>);
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<Self, tokio::task::JoinError> {
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())))
}
}
+2 -3
View File
@@ -182,10 +182,9 @@ impl DbType {
self,
) -> crate::Result<maxminddb::Reader<maxminddb::Mmap>> {
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?
+1 -1
View File
@@ -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))?;