Don't dispose managed CancellationTokenSource (#6139)

This commit is contained in:
Cody Robibero 2021-06-04 06:36:58 -06:00 committed by GitHub
parent b060d9d0f1
commit 9154f20b34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 36 additions and 4 deletions

View File

@ -1190,7 +1190,8 @@ namespace Jellyfin.Api.Controllers
throw new ArgumentException("StartTimeTicks is not allowed."); 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; var cancellationToken = cancellationTokenSource.Token;
using var state = await StreamingHelpers.GetStreamingState( using var state = await StreamingHelpers.GetStreamingState(

View File

@ -265,6 +265,7 @@ namespace Jellyfin.Api.Controllers
EnableSubtitlesInManifest = enableSubtitlesInManifest ?? true EnableSubtitlesInManifest = enableSubtitlesInManifest ?? true
}; };
// CTS lifecycle is managed internally.
var cancellationTokenSource = new CancellationTokenSource(); var cancellationTokenSource = new CancellationTokenSource();
using var state = await StreamingHelpers.GetStreamingState( using var state = await StreamingHelpers.GetStreamingState(
streamingRequest, streamingRequest,

View File

@ -373,6 +373,7 @@ namespace Jellyfin.Api.Controllers
[FromQuery] Dictionary<string, string> streamOptions) [FromQuery] Dictionary<string, string> streamOptions)
{ {
var isHeadRequest = Request.Method == System.Net.WebRequestMethods.Http.Head; var isHeadRequest = Request.Method == System.Net.WebRequestMethods.Http.Head;
// CTS lifecycle is managed internally.
var cancellationTokenSource = new CancellationTokenSource(); var cancellationTokenSource = new CancellationTokenSource();
var streamingRequest = new VideoRequestDto var streamingRequest = new VideoRequestDto
{ {

View File

@ -97,6 +97,8 @@ namespace Jellyfin.Api.Helpers
} }
bool isHeadRequest = _httpContextAccessor.HttpContext.Request.Method == System.Net.WebRequestMethods.Http.Head; bool isHeadRequest = _httpContextAccessor.HttpContext.Request.Method == System.Net.WebRequestMethods.Http.Head;
// CTS lifecycle is managed internally.
var cancellationTokenSource = new CancellationTokenSource(); var cancellationTokenSource = new CancellationTokenSource();
using var state = await StreamingHelpers.GetStreamingState( using var state = await StreamingHelpers.GetStreamingState(

View File

@ -106,6 +106,7 @@ namespace Jellyfin.Api.Helpers
bool enableAdaptiveBitrateStreaming) bool enableAdaptiveBitrateStreaming)
{ {
var isHeadRequest = _httpContextAccessor.HttpContext?.Request.Method == WebRequestMethods.Http.Head; var isHeadRequest = _httpContextAccessor.HttpContext?.Request.Method == WebRequestMethods.Http.Head;
// CTS lifecycle is managed internally.
var cancellationTokenSource = new CancellationTokenSource(); var cancellationTokenSource = new CancellationTokenSource();
return await GetMasterPlaylistInternal( return await GetMasterPlaylistInternal(
streamingRequest, streamingRequest,

View File

@ -269,7 +269,7 @@ namespace Jellyfin.Api.Helpers
{ {
_activeTranscodingJobs.Remove(job); _activeTranscodingJobs.Remove(job);
if (!job.CancellationTokenSource!.IsCancellationRequested) if (job.CancellationTokenSource?.IsCancellationRequested == false)
{ {
job.CancellationTokenSource.Cancel(); job.CancellationTokenSource.Cancel();
} }
@ -751,7 +751,7 @@ namespace Jellyfin.Api.Helpers
_logger.LogError("FFmpeg exited with code {0}", process.ExitCode); _logger.LogError("FFmpeg exited with code {0}", process.ExitCode);
} }
process.Dispose(); job.Dispose();
} }
private async Task AcquireResources(StreamState state, CancellationTokenSource cancellationTokenSource) private async Task AcquireResources(StreamState state, CancellationTokenSource cancellationTokenSource)

View File

@ -11,7 +11,7 @@ namespace Jellyfin.Api.Models.PlaybackDtos
/// <summary> /// <summary>
/// Class TranscodingJob. /// Class TranscodingJob.
/// </summary> /// </summary>
public class TranscodingJobDto public class TranscodingJobDto : IDisposable
{ {
/// <summary> /// <summary>
/// The process lock. /// 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;
}
}
} }
} }