Skip to content

Commit 6b076a2

Browse files
authored
fs: wait for in-flight ops before cloning File (#5803)
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
1 parent 910a1e2 commit 6b076a2

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

tokio/src/fs/file.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@ impl File {
399399
/// # }
400400
/// ```
401401
pub async fn try_clone(&self) -> io::Result<File> {
402+
self.inner.lock().await.complete_inflight().await;
402403
let std = self.std.clone();
403404
let std_file = asyncify(move || std.try_clone()).await?;
404405
Ok(File::from_std(std_file))

0 commit comments

Comments
 (0)