Skip to content

Commit

Permalink
Fixed disposable not being called (jellyfin#10613)
Browse files Browse the repository at this point in the history
* Fixed disposable not being called

* PulledUp usage of IAsyncDisposable for sessioninfo

Co-authored-by: Patrick Barron <barronpm@gmail.com>
  • Loading branch information
JPVenson and barronpm authored Jan 14, 2024
1 parent d402241 commit 3ce1671
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 28 deletions.
12 changes: 6 additions & 6 deletions Emby.Server.Implementations/Session/SessionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ private void OnSessionStarted(SessionInfo info)
_logger);
}

private void OnSessionEnded(SessionInfo info)
private async ValueTask OnSessionEnded(SessionInfo info)
{
EventHelper.QueueEventIfNotNull(
SessionEnded,
Expand All @@ -202,7 +202,7 @@ private void OnSessionEnded(SessionInfo info)

_eventManager.Publish(new SessionEndedEventArgs(info));

info.Dispose();
await info.DisposeAsync().ConfigureAwait(false);
}

/// <inheritdoc />
Expand Down Expand Up @@ -301,12 +301,12 @@ public async Task CloseIfNeededAsync(SessionInfo session)
await _mediaSourceManager.CloseLiveStream(session.PlayState.LiveStreamId).ConfigureAwait(false);
}

OnSessionEnded(session);
await OnSessionEnded(session).ConfigureAwait(false);
}
}

/// <inheritdoc />
public void ReportSessionEnded(string sessionId)
public async ValueTask ReportSessionEnded(string sessionId)
{
CheckDisposed();
var session = GetSession(sessionId, false);
Expand All @@ -317,7 +317,7 @@ public void ReportSessionEnded(string sessionId)

_activeConnections.TryRemove(key, out _);

OnSessionEnded(session);
await OnSessionEnded(session).ConfigureAwait(false);
}
}

Expand Down Expand Up @@ -1590,7 +1590,7 @@ public async Task Logout(Device device)
{
try
{
ReportSessionEnded(session.Id);
await ReportSessionEnded(session.Id).ConfigureAwait(false);
}
catch (Exception ex)
{
Expand Down
3 changes: 2 additions & 1 deletion MediaBrowser.Controller/Session/ISessionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ public interface ISessionManager
/// 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.
Expand Down
28 changes: 7 additions & 21 deletions MediaBrowser.Controller/Session/SessionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -374,33 +374,14 @@ public void StopAutomaticProgress()
}
}

/// <inheritdoc />
public void Dispose()
{
_disposed = true;

StopAutomaticProgress();

var controllers = SessionControllers.ToList();
SessionControllers = Array.Empty<ISessionController>();

foreach (var controller in controllers)
{
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();
SessionControllers = Array.Empty<ISessionController>();

foreach (var controller in controllers)
{
Expand All @@ -409,6 +390,11 @@ public async ValueTask DisposeAsync()
_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();
}
}
}
}
Expand Down

0 comments on commit 3ce1671

Please sign in to comment.