diff --git a/src/interpreter/mod.rs b/src/interpreter/mod.rs index fbc90028..215c935f 100644 --- a/src/interpreter/mod.rs +++ b/src/interpreter/mod.rs @@ -450,9 +450,27 @@ impl IoClient { // Flush the data to ensure it's written to disk match file_clone.flush().await { Ok(_) => { - // Try to sync to disk for durability, but don't fail if it's not supported - let _ = file_clone.sync_all().await; - Ok(()) + // Sync to disk for durability + match file_clone.sync_all().await { + Ok(_) => Ok(()), + Err(e) => { + // On Windows, sync_all can fail with "Access denied" in concurrent scenarios + // This is often a limitation of Windows filesystem, not a real error + if cfg!(windows) + && e.kind() == std::io::ErrorKind::PermissionDenied + { + // Log warning but don't fail - flush() already ensured data reaches OS buffers + eprintln!( + "Warning: Windows file sync limitation encountered: {}", + e + ); + Ok(()) + } else { + // On other platforms or different error types, this is a real failure + Err(format!("Failed to sync file to disk: {e}")) + } + } + } } Err(e) => Err(format!("Failed to flush file: {e}")), } @@ -481,9 +499,25 @@ impl IoClient { // Flush the file before closing to ensure all data is written to disk match file.flush().await { Ok(_) => { - // Try to sync to disk for durability, but don't fail if it's not supported - let _ = file.sync_all().await; - Ok(()) + // Sync to disk for durability + match file.sync_all().await { + Ok(_) => Ok(()), + Err(e) => { + // On Windows, sync_all can fail with "Access denied" in concurrent scenarios + // This is often a limitation of Windows filesystem, not a real error + if cfg!(windows) && e.kind() == std::io::ErrorKind::PermissionDenied { + // Log warning but don't fail - flush() already ensured data reaches OS buffers + eprintln!( + "Warning: Windows file sync limitation encountered: {}", + e + ); + Ok(()) + } else { + // On other platforms or different error types, this is a real failure + Err(format!("Failed to sync file during close: {e}")) + } + } + } } Err(e) => Err(format!("Failed to flush file during close: {e}")), } @@ -507,9 +541,27 @@ impl IoClient { // Flush the data to ensure it's written to disk match file.flush().await { Ok(_) => { - // Try to sync to disk for durability, but don't fail if it's not supported - let _ = file.sync_all().await; - Ok(()) + // Sync to disk for durability + match file.sync_all().await { + Ok(_) => Ok(()), + Err(e) => { + // On Windows, sync_all can fail with "Access denied" in concurrent scenarios + // This is often a limitation of Windows filesystem, not a real error + if cfg!(windows) + && e.kind() == std::io::ErrorKind::PermissionDenied + { + // Log warning but don't fail - flush() already ensured data reaches OS buffers + eprintln!( + "Warning: Windows file sync limitation encountered: {}", + e + ); + Ok(()) + } else { + // On other platforms or different error types, this is a real failure + Err(format!("Failed to sync appended data to disk: {e}")) + } + } + } } Err(e) => Err(format!("Failed to flush appended data: {e}")), }