about summary refs log tree commit diff
path: root/tvix/store/src
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2023-05-23T11·15+0300
committerflokli <flokli@flokli.de>2023-05-25T05·06+0000
commit92b6d15da3ff7717d8d480fed4c31f68924656f8 (patch)
tree3ad9a4984c004cf697ad48ae5134662fd2aeb534 /tvix/store/src
parent24cbf93729d3ec202c690adc607364ab010e0c7c (diff)
fix(tvix/store/bin): use spawn_blocking to call import_path r/6197
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 <tazjin@tvl.su>
Tested-by: BuildkiteCI
Autosubmit: flokli <flokli@flokli.de>
Diffstat (limited to 'tvix/store/src')
-rw-r--r--tvix/store/src/bin/tvix-store.rs24
1 files changed, 14 insertions, 10 deletions
diff --git a/tvix/store/src/bin/tvix-store.rs b/tvix/store/src/bin/tvix-store.rs
index dbd9e2986e24..8966be211fb2 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<dyn std::error::Error>> {
                 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) => {