Skip to content

Commit

Permalink
Drop DirEntries as soon as possible to avoid running out of open file…
Browse files Browse the repository at this point in the history
…-descriptors
  • Loading branch information
wykurz committed Jan 13, 2025
1 parent 3cd9c20 commit 2288743
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
7 changes: 6 additions & 1 deletion common/src/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,9 @@ pub async fn cmp(
|| async move { cmp(prog_track, &entry_path, &dst_path, &log, &settings).await };
join_set.spawn(do_cmp());
}

// unfortunately ReadDir is opening file-descriptors and there's not a good way to limit this,
// one thing we CAN do however is to drop it as soon as we're done with it
drop(src_entries);
event!(Level::DEBUG, "process contents of 'dst' directory");
let mut dst_entries = tokio::fs::read_dir(dst)
.await
Expand Down Expand Up @@ -249,6 +251,9 @@ pub async fn cmp(
)
.await?;
}
// unfortunately ReadDir is opening file-descriptors and there's not a good way to limit this,
// one thing we CAN do however is to drop it as soon as we're done with it
drop(dst_entries);
while let Some(res) = join_set.join_next().await {
match res? {
Ok(summary) => cmp_summary = cmp_summary + summary,
Expand Down
3 changes: 3 additions & 0 deletions common/src/copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,9 @@ pub async fn copy(
};
join_set.spawn(do_copy());
}
// unfortunately ReadDir is opening file-descriptors and there's not a good way to limit this,
// one thing we CAN do however is to drop it as soon as we're done with it
drop(entries);
while let Some(res) = join_set.join_next().await {
match res {
Ok(result) => match result {
Expand Down
6 changes: 6 additions & 0 deletions common/src/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,9 @@ pub async fn link(
};
join_set.spawn(do_link());
}
// unfortunately ReadDir is opening file-descriptors and there's not a good way to limit this,
// one thing we CAN do however is to drop it as soon as we're done with it
drop(src_entries);
// only process update if the path was provided and the directory is present
if update_metadata_opt.is_some() {
let update = update.as_ref().unwrap();
Expand Down Expand Up @@ -476,6 +479,9 @@ pub async fn link(
};
join_set.spawn(do_copy());
}
// unfortunately ReadDir is opening file-descriptors and there's not a good way to limit this,
// one thing we CAN do however is to drop it as soon as we're done with it
drop(update_entries);
}
while let Some(res) = join_set.join_next().await {
match res {
Expand Down
3 changes: 3 additions & 0 deletions common/src/rm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ pub async fn rm(
let do_rm = || async move { rm(prog_track, &entry_path, &settings).await };
join_set.spawn(do_rm());
}
// unfortunately ReadDir is opening file-descriptors and there's not a good way to limit this,
// one thing we CAN do however is to drop it as soon as we're done with it
drop(entries);
let mut rm_summary = RmSummary {
directories_removed: 0,
..Default::default()
Expand Down

0 comments on commit 2288743

Please sign in to comment.