Skip to content

Commit

Permalink
fix(iroh): shutdown sync engine on iroh node shutdown (#2131)
Browse files Browse the repository at this point in the history
- make sure the sync engine is shutdown in time
- enable `fs-store` by default
  • Loading branch information
dignifiedquire authored Apr 2, 2024
1 parent 6417816 commit 35a1cdd
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion iroh/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ clap = { version = "4", features = ["derive"], optional = true }
indicatif = { version = "0.17", features = ["tokio"], optional = true }

[features]
default = ["metrics"]
default = ["metrics", "fs-store"]
metrics = ["iroh-metrics", "iroh-bytes/metrics"]
fs-store = ["iroh-bytes/fs-store"]
test = []
Expand Down
22 changes: 21 additions & 1 deletion iroh/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ impl<D> NodeInner<D> {
}
}

#[cfg(all(test, feature = "fs-store"))]
#[cfg(test)]
mod tests {
use std::path::Path;
use std::time::Duration;
Expand Down Expand Up @@ -387,4 +387,24 @@ mod tests {

Ok(())
}

#[cfg(feature = "fs-store")]
#[tokio::test]
async fn test_shutdown() -> Result<()> {
let _guard = iroh_test::logging::setup();

let iroh_root = tempfile::TempDir::new()?;
{
let iroh = Node::persistent(iroh_root.path()).await?.spawn().await?;
let doc = iroh.docs.create().await?;
drop(doc);
iroh.shutdown();
iroh.await?;
}

let iroh = Node::persistent(iroh_root.path()).await?.spawn().await?;
let _doc = iroh.docs.create().await?;

Ok(())
}
}
4 changes: 3 additions & 1 deletion iroh/src/node/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,13 +438,15 @@ where
debug!(me = ?server.node_id(), "gossip initial update: {local_endpoints:?}");
gossip.update_endpoints(&local_endpoints).ok();
}

loop {
tokio::select! {
biased;
_ = cancel_token.cancelled() => {
// clean shutdown of the blobs db to close the write transaction
handler.inner.db.shutdown().await;
if let Err(err) = handler.inner.sync.shutdown().await {
warn!("sync shutdown error: {:?}", err);
}
break
},
// handle rpc requests. This will do nothing if rpc is not configured, since
Expand Down

0 comments on commit 35a1cdd

Please sign in to comment.