Skip to content

Commit

Permalink
fix(common): Synchronize file to disk in NativeIO
Browse files Browse the repository at this point in the history
Fixes a rare synchronization error in the `NativeIO`, where when
fetching is happening very fast concurrently, the file's contents may
not be synced to disk fast enough for the other end of the pipe to
recognize.
  • Loading branch information
clabby committed Jun 16, 2024
1 parent 877f22e commit 03d3283
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions crates/common/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ mod native_io {
file.seek(SeekFrom::Current(-(n as i64)))
.map_err(|e| anyhow!("Failed to reset file cursor to 0: {e}"))?;

// Attempt to sync the file to disk. This is a best-effort operation and should not
// throw if it fails.
let _ = file.sync_all();

Ok(n)
}

Expand All @@ -98,6 +102,10 @@ mod native_io {
let n =
file.read(buf).map_err(|e| anyhow!("Error reading from file descriptor: {e}"))?;

// Attempt to sync the file to disk. This is a best-effort operation and should not
// throw if it fails.
let _ = file.sync_all();

Ok(n)
}

Expand Down

0 comments on commit 03d3283

Please sign in to comment.