aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-06 04:34:57 +0100
committertv <tv@krebsco.de>2026-11-06 04:34:57 +0100
commitceeec6f661e13a2d9fc7d28f88450f6d45af5c43 (patch)
tree2ee8008c31d089719af0e58abcdc20974beb0bfd
parent0ac2a86253349a2d05874d258a179b5f73697dc5 (diff)
delta end guarded
-rw-r--r--src/swarm/sync.rs30
1 files changed, 23 insertions, 7 deletions
diff --git a/src/swarm/sync.rs b/src/swarm/sync.rs
index 5819bb7..a4ad30c 100644
--- a/src/swarm/sync.rs
+++ b/src/swarm/sync.rs
@@ -722,14 +722,12 @@ fn fetch_delta(state: &AppState, peer: &str, epoch: transport::Epoch, spec: tran
let state = state.clone();
let peer = peer.to_owned();
tokio::spawn(async move {
+ let done = DeltaDone {
+ state: state.clone(),
+ peer: peer.clone(),
+ };
let applied = download_and_apply_delta(&state, &peer, epoch, spec).await;
- // Those that offered meanwhile send what is still missing: our next message
- // says what we have now.
- for other in state.blobs.end_delta(&peer) {
- if other != peer {
- state.request_sync(&other);
- }
- }
+ drop(done);
match applied {
Ok(changed) => {
state.notify_store_changed();
@@ -746,6 +744,24 @@ fn fetch_delta(state: &AppState, peer: &str, epoch: transport::Epoch, spec: tran
});
}
+/// The delta download from `peer` ended, when dropped: however it ended, a panic
+/// included, the next may start (`Blobs::end_delta`), and those that offered meanwhile
+/// send what is still missing (our next message says what we have now).
+struct DeltaDone {
+ state: AppState,
+ peer: String,
+}
+
+impl Drop for DeltaDone {
+ fn drop(&mut self) {
+ for other in self.state.blobs.end_delta(&self.peer) {
+ if other != self.peer {
+ self.state.request_sync(&other);
+ }
+ }
+ }
+}
+
/// Returns whether our heads changed.
async fn download_and_apply_delta(
state: &AppState,