Skip to content

Commit

Permalink
fs: wait for in-flight ops before cloning File (#5803)
Browse files Browse the repository at this point in the history
If there is an ongoing operation on a file, wait for that to complete
before performing the clone in `File::try_clone`. This avoids a race
between the ongoing operation and any subsequent operations performed on
the clone.

Fixes: #5759
  • Loading branch information
djmitche authored Jun 27, 2023
1 parent 910a1e2 commit 6b076a2
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions tokio/src/fs/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ impl File {
/// # }
/// ```
pub async fn try_clone(&self) -> io::Result<File> {
self.inner.lock().await.complete_inflight().await;
let std = self.std.clone();
let std_file = asyncify(move || std.try_clone()).await?;
Ok(File::from_std(std_file))
Expand Down

0 comments on commit 6b076a2

Please sign in to comment.