From cdd838168d617f70fc04fe7f23846810e7e07082 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 16 Jun 2022 13:39:57 +0200 Subject: [PATCH] Fix live ending job that breaks new live session --- .../job-queue/handlers/video-live-ending.ts | 19 +++++++++++-------- server/lib/live/live-manager.ts | 1 + server/tests/api/live/live-save-replay.ts | 7 +++++++ shared/models/server/job.model.ts | 1 + 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/server/lib/job-queue/handlers/video-live-ending.ts b/server/lib/job-queue/handlers/video-live-ending.ts index 7607267f8..feec257fc 100644 --- a/server/lib/job-queue/handlers/video-live-ending.ts +++ b/server/lib/job-queue/handlers/video-live-ending.ts @@ -45,13 +45,13 @@ async function processVideoLiveEnding (job: Job) { LiveSegmentShaStore.Instance.cleanupShaSegments(liveVideo.uuid) if (live.saveReplay !== true) { - return cleanupLiveAndFederate({ live, video: liveVideo }) + return cleanupLiveAndFederate({ live, video: liveVideo, streamingPlaylistId: payload.streamingPlaylistId }) } if (live.permanentLive) { await saveReplayToExternalVideo({ liveVideo, liveSession, publishedAt: payload.publishedAt, replayDirectory: payload.replayDirectory }) - return cleanupLiveAndFederate({ live, video: liveVideo }) + return cleanupLiveAndFederate({ live, video: liveVideo, streamingPlaylistId: payload.streamingPlaylistId }) } return replaceLiveByReplay({ liveVideo, live, liveSession, replayDirectory: payload.replayDirectory }) @@ -233,15 +233,18 @@ async function assignReplayFilesToVideo (options: { async function cleanupLiveAndFederate (options: { live: MVideoLive video: MVideo + streamingPlaylistId: number }) { - const { live, video } = options + const { live, video, streamingPlaylistId } = options - const streamingPlaylist = await VideoStreamingPlaylistModel.loadHLSPlaylistByVideo(video.id) + const streamingPlaylist = await VideoStreamingPlaylistModel.loadWithVideo(streamingPlaylistId) - if (live.permanentLive) { - await cleanupPermanentLive(video, streamingPlaylist) - } else { - await cleanupNormalLive(video, streamingPlaylist) + if (streamingPlaylist) { + if (live.permanentLive) { + await cleanupPermanentLive(video, streamingPlaylist) + } else { + await cleanupNormalLive(video, streamingPlaylist) + } } try { diff --git a/server/lib/live/live-manager.ts b/server/lib/live/live-manager.ts index 0f14a6851..f2f064b49 100644 --- a/server/lib/live/live-manager.ts +++ b/server/lib/live/live-manager.ts @@ -416,6 +416,7 @@ class LiveManager { : undefined, liveSessionId: liveSession.id, + streamingPlaylistId: fullVideo.getHLSPlaylist()?.id, publishedAt: fullVideo.publishedAt.toISOString() } diff --git a/server/tests/api/live/live-save-replay.ts b/server/tests/api/live/live-save-replay.ts index 007af51e9..99d500711 100644 --- a/server/tests/api/live/live-save-replay.ts +++ b/server/tests/api/live/live-save-replay.ts @@ -12,6 +12,7 @@ import { createMultipleServers, doubleFollow, findExternalSavedVideo, + makeRawRequest, PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel, @@ -457,6 +458,12 @@ describe('Save replay setting', function () { // Streaming session #2 ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID }) await waitUntilLivePublishedOnAllServers(servers, liveVideoUUID) + + await wait(5000) + const video = await servers[0].videos.get({ id: liveVideoUUID }) + expect(video.streamingPlaylists).to.have.lengthOf(1) + await makeRawRequest(video.streamingPlaylists[0].playlistUrl) + await stopFfmpeg(ffmpegCommand) await waitUntilLiveWaitingOnAllServers(servers, liveVideoUUID) diff --git a/shared/models/server/job.model.ts b/shared/models/server/job.model.ts index bc5ffa570..073f15872 100644 --- a/shared/models/server/job.model.ts +++ b/shared/models/server/job.model.ts @@ -161,6 +161,7 @@ export interface VideoLiveEndingPayload { videoId: number publishedAt: string liveSessionId: number + streamingPlaylistId: number replayDirectory?: string }