From 92b6d15da3ff7717d8d480fed4c31f68924656f8 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Tue, 23 May 2023 14:15:26 +0300 Subject: fix(tvix/store/bin): use spawn_blocking to call import_path This operation is blocking, so it should be run inside a blocking tokio task. Tokio panics if it detects a blocking operation inside a non- blocking task, so cl/8619 would cause it to panic (as the GRPC clients use spawn_blocking under the hood). As spawn_blocking moves, and we can't clone `TvixStoreIO` (see cl/8614), we create a new instance of TvixStoreIO inside each loop iteration. Change-Id: I0c6548b3d4ac42d180d4c92314af8fd2b16510da Reviewed-on: https://cl.tvl.fyi/c/depot/+/8618 Reviewed-by: tazjin Tested-by: BuildkiteCI Autosubmit: flokli --- tvix/store/src/bin/tvix-store.rs | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'tvix/store/src/bin/tvix-store.rs') diff --git a/tvix/store/src/bin/tvix-store.rs b/tvix/store/src/bin/tvix-store.rs index dbd9e2986e..8966be211f 100644 --- a/tvix/store/src/bin/tvix-store.rs +++ b/tvix/store/src/bin/tvix-store.rs @@ -128,17 +128,21 @@ async fn main() -> Result<(), Box> { directory_service.clone(), ); - let mut io = TvixStoreIO::new( - blob_service, - directory_service, - path_info_service, - nar_calculation_service, - ); - for path in paths { - let path_info = io - .import_path_with_pathinfo(&path) - .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?; + let path_move = path.clone(); + + let mut io = TvixStoreIO::new( + blob_service.clone(), + directory_service.clone(), + path_info_service.clone(), + nar_calculation_service.clone(), + ); + + let path_info = tokio::task::spawn_blocking(move || { + io.import_path_with_pathinfo(&path_move) + .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string())) + }) + .await??; match path_info.node.unwrap().node.unwrap() { tvix_store::proto::node::Node::Directory(directory_node) => { -- cgit 1.4.1