Skip to content

Commit ea08b12

Browse files
authored
Snap sync: fix downloader not being "freed" on empty responses (#4101)
**Motivation** <!-- Why does this pull request exist? What are its goals? --> **Description** <!-- A clear and concise general description of the changes this PR introduces --> <!-- Link to issues: Resolves #111, Resolves #222 --> Closes #issue_number
1 parent 2ffa3b4 commit ea08b12

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

crates/networking/p2p/peer_handler.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -873,6 +873,10 @@ impl PeerHandler {
873873
}
874874

875875
if let Ok((accounts, peer_id, chunk_start_end)) = task_receiver.try_recv() {
876+
downloaders.entry(peer_id).and_modify(|downloader_is_free| {
877+
*downloader_is_free = true;
878+
});
879+
876880
if let Some((chunk_start, chunk_end)) = chunk_start_end {
877881
if chunk_start <= chunk_end {
878882
tasks_queue_not_started.push_back((chunk_start, chunk_end));
@@ -904,10 +908,6 @@ impl PeerHandler {
904908
.iter()
905909
.map(|unit| AccountState::from(unit.account.clone())),
906910
);
907-
908-
downloaders.entry(peer_id).and_modify(|downloader_is_free| {
909-
*downloader_is_free = true;
910-
});
911911
}
912912

913913
// Check if any dump account task finished
@@ -1233,6 +1233,11 @@ impl PeerHandler {
12331233
remaining_start,
12341234
remaining_end,
12351235
} = result;
1236+
1237+
downloaders.entry(peer_id).and_modify(|downloader_is_free| {
1238+
*downloader_is_free = true;
1239+
});
1240+
12361241
if remaining_start < remaining_end {
12371242
tasks_queue_not_started.push_back((remaining_start, remaining_end));
12381243
} else {
@@ -1256,10 +1261,6 @@ impl PeerHandler {
12561261
for (i, bytecode) in bytecodes.into_iter().enumerate() {
12571262
all_bytecodes[start_index + i] = bytecode;
12581263
}
1259-
1260-
downloaders.entry(peer_id).and_modify(|downloader_is_free| {
1261-
*downloader_is_free = true;
1262-
});
12631264
}
12641265

12651266
let peer_channels = self

0 commit comments

Comments
 (0)