From 098008e7f5d9ef453fda01dc9da298e24e8c655b Mon Sep 17 00:00:00 2001 From: Elliu <elliu@hashi.re> Date: Wed, 19 Feb 2025 19:56:20 +0100 Subject: [PATCH] SEARCH: fix tokio::spawn spawning block_on calling function --- lektord/src/app/routes.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lektord/src/app/routes.rs b/lektord/src/app/routes.rs index a6953bbc..cf231521 100644 --- a/lektord/src/app/routes.rs +++ b/lektord/src/app/routes.rs @@ -21,6 +21,7 @@ use lektor_utils::decode_base64_json; use rand::seq::SliceRandom; use std::ops::RangeBounds; use tokio::task::LocalSet; +use tokio::task::spawn_blocking; /// Get informations abount the lektord server. #[axum::debug_handler(state = LektorStatePtr)] @@ -557,7 +558,7 @@ macro_rules! extractor { => { $($match_pat:pat => $match_handle:expr,)+ } => |$arg:ident| $handle:expr $(,)? ) => { - async move { + move || { tokio::runtime::Builder::new_current_thread() .build() .context("failed to build the runtime")? @@ -578,7 +579,7 @@ pub(crate) async fn search( Path(uri): Path<String>, ) -> Result<Json<Vec<KId>>, LektordError> { let SearchData { from, regex } = decode_base64_json(uri)?; - Ok(tokio::spawn(extractor! { + Ok(spawn_blocking(extractor! { match from => { SearchFrom::Database => search_adaptors::database_extractor(&state).await, @@ -603,7 +604,7 @@ pub(crate) async fn count( Path(uri): Path<String>, ) -> Result<Json<usize>, LektordError> { let SearchData { from, regex } = decode_base64_json(uri)?; - Ok(tokio::spawn(extractor! { + Ok(spawn_blocking(extractor! { match from => { SearchFrom::Database => search_adaptors::database_extractor(&state).await, -- GitLab