瀏覽代碼

Use WriteThrough for ImageSaver

When writing an image to the disk, we use the completion of the async task as a signal indicating the completion of a write operation. However, this approach may not be entirely accurate, as the operating system can optimize IO operations by writing data to an intermediate cache instead of directly to the disk before completing the operation. This optimization can lead to a data race for our scanner, as subsequent tasks such as blurhash computation may attempt to read a file that has not yet been flushed from the volatile cache. Consequently, the data within the file becomes invalid, causing the blurhash computation task to fail.

Use WriteThrough mode to ensure the data is actual on disk before return to resolve this issue.
gnattu 4 月之前
父節點
當前提交
644df3585b
共有 1 個文件被更改,包括 1 次插入0 次删除
  1. 1 0
      MediaBrowser.Providers/Manager/ImageSaver.cs

+ 1 - 0
MediaBrowser.Providers/Manager/ImageSaver.cs

@@ -291,6 +291,7 @@ namespace MediaBrowser.Providers.Manager
 
                 var fileStreamOptions = AsyncFile.WriteOptions;
                 fileStreamOptions.Mode = FileMode.Create;
+                fileStreamOptions.Options = FileOptions.WriteThrough;
                 if (source.CanSeek)
                 {
                     fileStreamOptions.PreallocationSize = source.Length;