Fixed disposable not being called (#10613)

* Fixed disposable not being called

* PulledUp usage of IAsyncDisposable for sessioninfo

Co-authored-by: Patrick Barron <barronpm@gmail.com>
This commit is contained in:
JPVenson
2024-01-14 16:50:09 +01:00
committed by GitHub
parent d40224128c
commit 3ce16713dd
3 changed files with 16 additions and 29 deletions

View File

@@ -111,7 +111,8 @@ namespace MediaBrowser.Controller.Session
/// Reports the session ended.
/// </summary>
/// <param name="sessionId">The session identifier.</param>
void ReportSessionEnded(string sessionId);
/// <returns>Task.</returns>
ValueTask ReportSessionEnded(string sessionId);
/// <summary>
/// Sends the general command.

View File

@@ -19,7 +19,7 @@ namespace MediaBrowser.Controller.Session
/// <summary>
/// Class SessionInfo.
/// </summary>
public sealed class SessionInfo : IAsyncDisposable, IDisposable
public sealed class SessionInfo : IAsyncDisposable
{
// 1 second
private const long ProgressIncrement = 10000000;
@@ -374,8 +374,7 @@ namespace MediaBrowser.Controller.Session
}
}
/// <inheritdoc />
public void Dispose()
public async ValueTask DisposeAsync()
{
_disposed = true;
@@ -386,30 +385,17 @@ namespace MediaBrowser.Controller.Session
foreach (var controller in controllers)
{
if (controller is IDisposable disposable)
if (controller is IAsyncDisposable disposableAsync)
{
_logger.LogDebug("Disposing session controller asynchronously {TypeName}", disposableAsync.GetType().Name);
await disposableAsync.DisposeAsync().ConfigureAwait(false);
}
else if (controller is IDisposable disposable)
{
_logger.LogDebug("Disposing session controller synchronously {TypeName}", disposable.GetType().Name);
disposable.Dispose();
}
}
}
public async ValueTask DisposeAsync()
{
_disposed = true;
StopAutomaticProgress();
var controllers = SessionControllers.ToList();
foreach (var controller in controllers)
{
if (controller is IAsyncDisposable disposableAsync)
{
_logger.LogDebug("Disposing session controller asynchronously {TypeName}", disposableAsync.GetType().Name);
await disposableAsync.DisposeAsync().ConfigureAwait(false);
}
}
}
}
}