From 4d9e9f4a9d0c98e152f6e870baae7eaa2d5391ed Mon Sep 17 00:00:00 2001 From: Irevoire Date: Thu, 27 Oct 2022 13:12:42 +0200 Subject: [PATCH] isolate the search in another task In case there is a failure on milli's side that should avoid blocking the tokio main thread --- meilisearch-http/src/routes/indexes/search.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/meilisearch-http/src/routes/indexes/search.rs b/meilisearch-http/src/routes/indexes/search.rs index 8c901035d..af5da44a0 100644 --- a/meilisearch-http/src/routes/indexes/search.rs +++ b/meilisearch-http/src/routes/indexes/search.rs @@ -153,7 +153,7 @@ pub async fn search_with_url_query( let mut aggregate = SearchAggregator::from_query(&query, &req); let index = index_scheduler.index(&index_uid)?; - let search_result = perform_search(&index, query); + let search_result = tokio::task::spawn_blocking(move || perform_search(&index, query)).await?; if let Ok(ref search_result) = search_result { aggregate.succeed(search_result); } @@ -185,7 +185,7 @@ pub async fn search_with_post( let mut aggregate = SearchAggregator::from_query(&query, &req); let index = index_scheduler.index(&index_uid)?; - let search_result = perform_search(&index, query); + let search_result = tokio::task::spawn_blocking(move || perform_search(&index, query)).await?; if let Ok(ref search_result) = search_result { aggregate.succeed(search_result); }