mirror of
https://github.com/jellyfin/jellyfin
synced 2024-07-21 09:54:24 +00:00
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:
parent
d40224128c
commit
3ce16713dd
|
@ -189,7 +189,7 @@ namespace Emby.Server.Implementations.Session
|
||||||
_logger);
|
_logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnSessionEnded(SessionInfo info)
|
private async ValueTask OnSessionEnded(SessionInfo info)
|
||||||
{
|
{
|
||||||
EventHelper.QueueEventIfNotNull(
|
EventHelper.QueueEventIfNotNull(
|
||||||
SessionEnded,
|
SessionEnded,
|
||||||
|
@ -202,7 +202,7 @@ namespace Emby.Server.Implementations.Session
|
||||||
|
|
||||||
_eventManager.Publish(new SessionEndedEventArgs(info));
|
_eventManager.Publish(new SessionEndedEventArgs(info));
|
||||||
|
|
||||||
info.Dispose();
|
await info.DisposeAsync().ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
@ -301,12 +301,12 @@ namespace Emby.Server.Implementations.Session
|
||||||
await _mediaSourceManager.CloseLiveStream(session.PlayState.LiveStreamId).ConfigureAwait(false);
|
await _mediaSourceManager.CloseLiveStream(session.PlayState.LiveStreamId).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
OnSessionEnded(session);
|
await OnSessionEnded(session).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void ReportSessionEnded(string sessionId)
|
public async ValueTask ReportSessionEnded(string sessionId)
|
||||||
{
|
{
|
||||||
CheckDisposed();
|
CheckDisposed();
|
||||||
var session = GetSession(sessionId, false);
|
var session = GetSession(sessionId, false);
|
||||||
|
@ -317,7 +317,7 @@ namespace Emby.Server.Implementations.Session
|
||||||
|
|
||||||
_activeConnections.TryRemove(key, out _);
|
_activeConnections.TryRemove(key, out _);
|
||||||
|
|
||||||
OnSessionEnded(session);
|
await OnSessionEnded(session).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1590,7 +1590,7 @@ namespace Emby.Server.Implementations.Session
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ReportSessionEnded(session.Id);
|
await ReportSessionEnded(session.Id).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|
|
@ -111,7 +111,8 @@ namespace MediaBrowser.Controller.Session
|
||||||
/// Reports the session ended.
|
/// Reports the session ended.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sessionId">The session identifier.</param>
|
/// <param name="sessionId">The session identifier.</param>
|
||||||
void ReportSessionEnded(string sessionId);
|
/// <returns>Task.</returns>
|
||||||
|
ValueTask ReportSessionEnded(string sessionId);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sends the general command.
|
/// Sends the general command.
|
||||||
|
|
|
@ -19,7 +19,7 @@ namespace MediaBrowser.Controller.Session
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Class SessionInfo.
|
/// Class SessionInfo.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class SessionInfo : IAsyncDisposable, IDisposable
|
public sealed class SessionInfo : IAsyncDisposable
|
||||||
{
|
{
|
||||||
// 1 second
|
// 1 second
|
||||||
private const long ProgressIncrement = 10000000;
|
private const long ProgressIncrement = 10000000;
|
||||||
|
@ -374,8 +374,7 @@ namespace MediaBrowser.Controller.Session
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
public async ValueTask DisposeAsync()
|
||||||
public void Dispose()
|
|
||||||
{
|
{
|
||||||
_disposed = true;
|
_disposed = true;
|
||||||
|
|
||||||
|
@ -386,30 +385,17 @@ namespace MediaBrowser.Controller.Session
|
||||||
|
|
||||||
foreach (var controller in controllers)
|
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);
|
_logger.LogDebug("Disposing session controller synchronously {TypeName}", disposable.GetType().Name);
|
||||||
disposable.Dispose();
|
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue