diff --git a/Jellyfin.Api/Helpers/ProgressiveFileStream.cs b/Jellyfin.Api/Helpers/ProgressiveFileStream.cs
index e09f3dca94..b3566b6f80 100644
--- a/Jellyfin.Api/Helpers/ProgressiveFileStream.cs
+++ b/Jellyfin.Api/Helpers/ProgressiveFileStream.cs
@@ -79,13 +79,10 @@ namespace Jellyfin.Api.Helpers
///
public override async Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
{
- var eofCount = 0;
- const int EmptyReadLimit = 20;
-
int totalBytesRead = 0;
int remainingBytesToRead = count;
- while (eofCount < EmptyReadLimit && remainingBytesToRead > 0)
+ while (remainingBytesToRead > 0)
{
cancellationToken.ThrowIfCancellationRequested();
int bytesRead;
@@ -109,20 +106,15 @@ namespace Jellyfin.Api.Helpers
_job.BytesDownloaded = Math.Max(_job.BytesDownloaded ?? _bytesWritten, _bytesWritten);
}
}
-
- if (bytesRead == 0)
+ else
{
if (_job == null || _job.HasExited)
{
- eofCount++;
+ break;
}
await Task.Delay(100, cancellationToken).ConfigureAwait(false);
}
- else
- {
- eofCount = 0;
- }
}
return totalBytesRead;
@@ -148,17 +140,23 @@ namespace Jellyfin.Api.Helpers
return;
}
- if (disposing)
+ try
{
- _fileStream.Dispose();
-
- if (_job != null)
+ if (disposing)
{
- _transcodingJobHelper.OnTranscodeEndRequest(_job);
+ _fileStream.Dispose();
+
+ if (_job != null)
+ {
+ _transcodingJobHelper.OnTranscodeEndRequest(_job);
+ }
}
}
-
- _disposed = true;
+ finally
+ {
+ _disposed = true;
+ base.Dispose(disposing);
+ }
}
}
}