mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-05-13 04:06:31 +01:00
Fix live stream consumer leak when PositionTicks is negative
When a stalled HLS client sends ReportPlaybackStopped with a negative PositionTicks (e.g. HLS.js reporting position on buffer stall), the ArgumentOutOfRangeException was thrown before GetSession was called, causing CloseLiveStreamIfNeededAsync to never run. This left the ILiveStream.ConsumerCount permanently incremented, permanently holding a tuner open with no active viewer. Fix by acquiring the session and performing live stream cleanup before throwing the validation exception, so tuner resources are always freed even when playback reporting fails with invalid position data. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1025,15 +1025,22 @@ namespace Emby.Server.Implementations.Session
|
||||
|
||||
ArgumentNullException.ThrowIfNull(info);
|
||||
|
||||
if (info.PositionTicks.HasValue && info.PositionTicks.Value < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(info), "The PlaybackStopInfo's PositionTicks was negative.");
|
||||
}
|
||||
|
||||
var session = GetSession(info.SessionId);
|
||||
|
||||
session.StopAutomaticProgress();
|
||||
|
||||
if (info.PositionTicks.HasValue && info.PositionTicks.Value < 0)
|
||||
{
|
||||
// Ensure live stream is cleaned up before throwing, to prevent tuner
|
||||
// resource leaks when stalled clients report a negative PositionTicks.
|
||||
if (!string.IsNullOrEmpty(info.LiveStreamId))
|
||||
{
|
||||
await CloseLiveStreamIfNeededAsync(info.LiveStreamId, session.Id).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
throw new ArgumentOutOfRangeException(nameof(info), "The PlaybackStopInfo's PositionTicks was negative.");
|
||||
}
|
||||
|
||||
var libraryItem = info.ItemId.IsEmpty()
|
||||
? null
|
||||
: GetNowPlayingItem(session, info.ItemId);
|
||||
|
||||
Reference in New Issue
Block a user