Don't dispose managed CancellationTokenSource (#6139)
This commit is contained in:
parent
b060d9d0f1
commit
9154f20b34
|
@ -1190,7 +1190,8 @@ namespace Jellyfin.Api.Controllers
|
|||
throw new ArgumentException("StartTimeTicks is not allowed.");
|
||||
}
|
||||
|
||||
using var cancellationTokenSource = new CancellationTokenSource();
|
||||
// CTS lifecycle is managed internally.
|
||||
var cancellationTokenSource = new CancellationTokenSource();
|
||||
var cancellationToken = cancellationTokenSource.Token;
|
||||
|
||||
using var state = await StreamingHelpers.GetStreamingState(
|
||||
|
|
|
@ -265,6 +265,7 @@ namespace Jellyfin.Api.Controllers
|
|||
EnableSubtitlesInManifest = enableSubtitlesInManifest ?? true
|
||||
};
|
||||
|
||||
// CTS lifecycle is managed internally.
|
||||
var cancellationTokenSource = new CancellationTokenSource();
|
||||
using var state = await StreamingHelpers.GetStreamingState(
|
||||
streamingRequest,
|
||||
|
|
|
@ -373,6 +373,7 @@ namespace Jellyfin.Api.Controllers
|
|||
[FromQuery] Dictionary<string, string> streamOptions)
|
||||
{
|
||||
var isHeadRequest = Request.Method == System.Net.WebRequestMethods.Http.Head;
|
||||
// CTS lifecycle is managed internally.
|
||||
var cancellationTokenSource = new CancellationTokenSource();
|
||||
var streamingRequest = new VideoRequestDto
|
||||
{
|
||||
|
|
|
@ -97,6 +97,8 @@ namespace Jellyfin.Api.Helpers
|
|||
}
|
||||
|
||||
bool isHeadRequest = _httpContextAccessor.HttpContext.Request.Method == System.Net.WebRequestMethods.Http.Head;
|
||||
|
||||
// CTS lifecycle is managed internally.
|
||||
var cancellationTokenSource = new CancellationTokenSource();
|
||||
|
||||
using var state = await StreamingHelpers.GetStreamingState(
|
||||
|
|
|
@ -106,6 +106,7 @@ namespace Jellyfin.Api.Helpers
|
|||
bool enableAdaptiveBitrateStreaming)
|
||||
{
|
||||
var isHeadRequest = _httpContextAccessor.HttpContext?.Request.Method == WebRequestMethods.Http.Head;
|
||||
// CTS lifecycle is managed internally.
|
||||
var cancellationTokenSource = new CancellationTokenSource();
|
||||
return await GetMasterPlaylistInternal(
|
||||
streamingRequest,
|
||||
|
|
|
@ -269,7 +269,7 @@ namespace Jellyfin.Api.Helpers
|
|||
{
|
||||
_activeTranscodingJobs.Remove(job);
|
||||
|
||||
if (!job.CancellationTokenSource!.IsCancellationRequested)
|
||||
if (job.CancellationTokenSource?.IsCancellationRequested == false)
|
||||
{
|
||||
job.CancellationTokenSource.Cancel();
|
||||
}
|
||||
|
@ -751,7 +751,7 @@ namespace Jellyfin.Api.Helpers
|
|||
_logger.LogError("FFmpeg exited with code {0}", process.ExitCode);
|
||||
}
|
||||
|
||||
process.Dispose();
|
||||
job.Dispose();
|
||||
}
|
||||
|
||||
private async Task AcquireResources(StreamState state, CancellationTokenSource cancellationTokenSource)
|
||||
|
|
|
@ -11,7 +11,7 @@ namespace Jellyfin.Api.Models.PlaybackDtos
|
|||
/// <summary>
|
||||
/// Class TranscodingJob.
|
||||
/// </summary>
|
||||
public class TranscodingJobDto
|
||||
public class TranscodingJobDto : IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// The process lock.
|
||||
|
@ -249,5 +249,31 @@ namespace Jellyfin.Api.Models.PlaybackDtos
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dispose all resources.
|
||||
/// </summary>
|
||||
/// <param name="disposing">Whether to dispose all resources.</param>
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
Process?.Dispose();
|
||||
Process = null;
|
||||
KillTimer?.Dispose();
|
||||
KillTimer = null;
|
||||
CancellationTokenSource?.Dispose();
|
||||
CancellationTokenSource = null;
|
||||
TranscodingThrottler?.Dispose();
|
||||
TranscodingThrottler = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user