Skip to content

Commit 35a1cdd

Browse files
fix(iroh): shutdown sync engine on iroh node shutdown (#2131)
- make sure the sync engine is shutdown in time - enable `fs-store` by default
1 parent 6417816 commit 35a1cdd

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

iroh/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ clap = { version = "4", features = ["derive"], optional = true }
5757
indicatif = { version = "0.17", features = ["tokio"], optional = true }
5858

5959
[features]
60-
default = ["metrics"]
60+
default = ["metrics", "fs-store"]
6161
metrics = ["iroh-metrics", "iroh-bytes/metrics"]
6262
fs-store = ["iroh-bytes/fs-store"]
6363
test = []

iroh/src/node.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ impl<D> NodeInner<D> {
277277
}
278278
}
279279

280-
#[cfg(all(test, feature = "fs-store"))]
280+
#[cfg(test)]
281281
mod tests {
282282
use std::path::Path;
283283
use std::time::Duration;
@@ -387,4 +387,24 @@ mod tests {
387387

388388
Ok(())
389389
}
390+
391+
#[cfg(feature = "fs-store")]
392+
#[tokio::test]
393+
async fn test_shutdown() -> Result<()> {
394+
let _guard = iroh_test::logging::setup();
395+
396+
let iroh_root = tempfile::TempDir::new()?;
397+
{
398+
let iroh = Node::persistent(iroh_root.path()).await?.spawn().await?;
399+
let doc = iroh.docs.create().await?;
400+
drop(doc);
401+
iroh.shutdown();
402+
iroh.await?;
403+
}
404+
405+
let iroh = Node::persistent(iroh_root.path()).await?.spawn().await?;
406+
let _doc = iroh.docs.create().await?;
407+
408+
Ok(())
409+
}
390410
}

iroh/src/node/builder.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,13 +438,15 @@ where
438438
debug!(me = ?server.node_id(), "gossip initial update: {local_endpoints:?}");
439439
gossip.update_endpoints(&local_endpoints).ok();
440440
}
441-
442441
loop {
443442
tokio::select! {
444443
biased;
445444
_ = cancel_token.cancelled() => {
446445
// clean shutdown of the blobs db to close the write transaction
447446
handler.inner.db.shutdown().await;
447+
if let Err(err) = handler.inner.sync.shutdown().await {
448+
warn!("sync shutdown error: {:?}", err);
449+
}
448450
break
449451
},
450452
// handle rpc requests. This will do nothing if rpc is not configured, since

0 commit comments

Comments
 (0)