The Free Software Media System - Server Backend & API
Backport pull request #13033 from jellyfin/release-10.10.z
goknsh924c80a209be
diff --git a/Jellyfin.Server/Infrastructure/SymlinkFollowingPhysicalFileResultExecutor.cs b/Jellyfin.Server/Infrastructure/SymlinkFollowingPhysicalFileResultExecutor.csindex 801026c549..901ed55be6 100644--- a/Jellyfin.Server/Infrastructure/SymlinkFollowingPhysicalFileResultExecutor.cs+++ b/Jellyfin.Server/Infrastructure/SymlinkFollowingPhysicalFileResultExecutor.cs@@ -101,7 +101,7 @@ namespace Jellyfin.Server.Infrastructurecount: null);}- private async Task SendFileAsync(string filePath, HttpResponse response, long offset, long? count)+ private async Task SendFileAsync(string filePath, HttpResponse response, long offset, long? count, CancellationToken cancellationToken = default){var fileInfo = GetFileInfo(filePath);if (offset < 0 || offset > fileInfo.Length)@@ -118,6 +118,9 @@ namespace Jellyfin.Server.Infrastructure// Copied from SendFileFallback.SendFileAsyncconst int BufferSize = 1024 * 16;+ var useRequestAborted = !cancellationToken.CanBeCanceled;+ var localCancel = useRequestAborted ? response.HttpContext.RequestAborted : cancellationToken;+var fileStream = new FileStream(filePath,FileMode.Open,@@ -127,10 +130,17 @@ namespace Jellyfin.Server.Infrastructureoptions: FileOptions.Asynchronous | FileOptions.SequentialScan);await using (fileStream.ConfigureAwait(false)){- fileStream.Seek(offset, SeekOrigin.Begin);- await StreamCopyOperation- .CopyToAsync(fileStream, response.Body, count, BufferSize, CancellationToken.None)- .ConfigureAwait(true);+ try+ {+ localCancel.ThrowIfCancellationRequested();+ fileStream.Seek(offset, SeekOrigin.Begin);+ await StreamCopyOperation+ .CopyToAsync(fileStream, response.Body, count, BufferSize, localCancel)+ .ConfigureAwait(true);+ }+ catch (OperationCanceledException) when (useRequestAborted)+ {+ }}}