From 6b076a27437a94f0c0e4d506188bef26c53896ee Mon Sep 17 00:00:00 2001 From: "Dustin J. Mitchell" Date: Tue, 27 Jun 2023 04:19:03 -0400 Subject: [PATCH] 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 --- tokio/src/fs/file.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/tokio/src/fs/file.rs b/tokio/src/fs/file.rs index f4634d9ebb8..74f91958d0d 100644 --- a/tokio/src/fs/file.rs +++ b/tokio/src/fs/file.rs @@ -399,6 +399,7 @@ impl File { /// # } /// ``` pub async fn try_clone(&self) -> io::Result { + 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))