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
This commit is contained in:
Dustin J. Mitchell
2023-06-27 10:19:03 +02:00
committed by GitHub
parent 910a1e2fcf
commit 6b076a2743
+1
View File
@@ -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))