]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Fix removed sha segments on fast restream
authorChocobozzz <me@florianbigard.com>
Fri, 24 Jun 2022 07:34:56 +0000 (09:34 +0200)
committerChocobozzz <me@florianbigard.com>
Fri, 24 Jun 2022 07:35:30 +0000 (09:35 +0200)
server/initializers/constants.ts
server/lib/job-queue/handlers/video-live-ending.ts
server/lib/live/live-manager.ts
server/lib/live/live-utils.ts
server/tests/api/live/live-fast-restream.ts

index 6c6628d2862bc9b67d8d4cec32281a7eac16bc11..88f370a9a02b52b3bf44324dbe28d53903b22b6f 100644 (file)
@@ -865,7 +865,7 @@ if (isTestInstance() === true) {
 
   PLUGIN_EXTERNAL_AUTH_TOKEN_LIFETIME = 5000
 
-  VIDEO_LIVE.CLEANUP_DELAY = getIntEnv('PEERTUBE_TEST_CONSTANTS.VIDEO_LIVE.CLEANUP_DELAY') ?? 5000
+  VIDEO_LIVE.CLEANUP_DELAY = getIntEnv('PEERTUBE_TEST_CONSTANTS_VIDEO_LIVE_CLEANUP_DELAY') ?? 5000
   VIDEO_LIVE.SEGMENT_TIME_SECONDS.DEFAULT_LATENCY = 2
   VIDEO_LIVE.SEGMENT_TIME_SECONDS.SMALL_LATENCY = 1
   VIDEO_LIVE.EDGE_LIVE_DELAY_SEGMENTS_NOTIFICATION = 1
index 450bda2fdf97be765150bc4ef8ce8c2dd72bd4ae..b2c42664a57c10b3913d5eb16207ca908169194a 100644 (file)
@@ -4,13 +4,8 @@ import { join } from 'path'
 import { ffprobePromise, getAudioStream, getVideoStreamDimensionsInfo, getVideoStreamDuration } from '@server/helpers/ffmpeg'
 import { getLocalVideoActivityPubUrl } from '@server/lib/activitypub/url'
 import { federateVideoIfNeeded } from '@server/lib/activitypub/videos'
-import { cleanupUnsavedNormalLive, cleanupPermanentLive, cleanupTMPLiveFiles, LiveSegmentShaStore } from '@server/lib/live'
-import {
-  generateHLSMasterPlaylistFilename,
-  generateHlsSha256SegmentsFilename,
-  getLiveDirectory,
-  getLiveReplayBaseDirectory
-} from '@server/lib/paths'
+import { cleanupPermanentLive, cleanupTMPLiveFiles, cleanupUnsavedNormalLive } from '@server/lib/live'
+import { generateHLSMasterPlaylistFilename, generateHlsSha256SegmentsFilename, getLiveReplayBaseDirectory } from '@server/lib/paths'
 import { generateVideoMiniature } from '@server/lib/thumbnail'
 import { generateHlsPlaylistResolutionFromTS } from '@server/lib/transcoding/transcoding'
 import { moveToNextState } from '@server/lib/video-state'
@@ -44,8 +39,6 @@ async function processVideoLiveEnding (job: Job) {
     return
   }
 
-  LiveSegmentShaStore.Instance.cleanupShaSegments(liveVideo.uuid)
-
   if (live.saveReplay !== true) {
     return cleanupLiveAndFederate({ live, video: liveVideo, streamingPlaylistId: payload.streamingPlaylistId })
   }
@@ -137,7 +130,7 @@ async function replaceLiveByReplay (options: {
 }) {
   const { liveVideo, liveSession, live, replayDirectory } = options
 
-  await cleanupTMPLiveFiles(getLiveDirectory(liveVideo))
+  await cleanupTMPLiveFiles(liveVideo)
 
   await live.destroy()
 
index f2f064b49bc29c596e62b302c76139f3f2fb7db2..d499b4b1af3e245d593fc4af21cb3fa5ab7aa928 100644 (file)
@@ -27,7 +27,6 @@ import { JobQueue } from '../job-queue'
 import { generateHLSMasterPlaylistFilename, generateHlsSha256SegmentsFilename, getLiveReplayBaseDirectory } from '../paths'
 import { PeerTubeSocket } from '../peertube-socket'
 import { LiveQuotaStore } from './live-quota-store'
-import { LiveSegmentShaStore } from './live-segment-sha-store'
 import { cleanupPermanentLive } from './live-utils'
 import { MuxingSession } from './shared'
 
@@ -219,9 +218,7 @@ class LiveManager {
       return this.abortSession(sessionId)
     }
 
-    // Cleanup old potential live files (could happen with a permanent live)
-    LiveSegmentShaStore.Instance.cleanupShaSegments(video.uuid)
-
+    // Cleanup old potential live (could happen with a permanent live)
     const oldStreamingPlaylist = await VideoStreamingPlaylistModel.loadHLSPlaylistByVideo(video.id)
     if (oldStreamingPlaylist) {
       if (!videoLive.permanentLive) throw new Error('Found previous session in a non permanent live: ' + video.uuid)
index 6305a97a86fadcabd68dee1cb450a46248db6fc4..bba8766428aa409a9daaff816ac1136d060cd0eb 100644 (file)
@@ -3,6 +3,7 @@ import { basename, join } from 'path'
 import { logger } from '@server/helpers/logger'
 import { MStreamingPlaylist, MVideo } from '@server/types/models'
 import { getLiveDirectory } from '../paths'
+import { LiveSegmentShaStore } from './live-segment-sha-store'
 
 function buildConcatenatedName (segmentOrPlaylistPath: string) {
   const num = basename(segmentOrPlaylistPath).match(/^(\d+)(-|\.)/)
@@ -11,9 +12,7 @@ function buildConcatenatedName (segmentOrPlaylistPath: string) {
 }
 
 async function cleanupPermanentLive (video: MVideo, streamingPlaylist: MStreamingPlaylist) {
-  const hlsDirectory = getLiveDirectory(video)
-
-  await cleanupTMPLiveFiles(hlsDirectory)
+  await cleanupTMPLiveFiles(video)
 
   await streamingPlaylist.destroy()
 }
@@ -24,11 +23,19 @@ async function cleanupUnsavedNormalLive (video: MVideo, streamingPlaylist: MStre
   await remove(hlsDirectory)
 
   await streamingPlaylist.destroy()
+
+  LiveSegmentShaStore.Instance.cleanupShaSegments(video.uuid)
 }
 
-async function cleanupTMPLiveFiles (hlsDirectory: string) {
+async function cleanupTMPLiveFiles (video: MVideo) {
+  const hlsDirectory = getLiveDirectory(video)
+
+  LiveSegmentShaStore.Instance.cleanupShaSegments(video.uuid)
+
   if (!await pathExists(hlsDirectory)) return
 
+  logger.info('Cleanup TMP live files of %s.', hlsDirectory)
+
   const files = await readdir(hlsDirectory)
 
   for (const filename of files) {
index 4b5d041eca5471ab06e0b02734c52cc29d75fa2e..b524cbe7f3ef092a6f7e60e8d4addddd27d60570 100644 (file)
@@ -57,13 +57,14 @@ describe('Fast restream in live', function () {
   }
 
   async function ensureLastLiveWorks (liveId: string) {
-    // Equivalent to PEERTUBE_TEST_CONSTANTS.VIDEO_LIVE.CLEANUP_DELAY
+    // Equivalent to PEERTUBE_TEST_CONSTANTS_VIDEO_LIVE_CLEANUP_DELAY
     for (let i = 0; i < 100; i++) {
       const video = await server.videos.get({ id: liveId })
       expect(video.streamingPlaylists).to.have.lengthOf(1)
 
       await server.live.getSegment({ videoUUID: liveId, segment: 0, playlistNumber: 0 })
       await makeRawRequest(video.streamingPlaylists[0].playlistUrl, HttpStatusCode.OK_200)
+      await makeRawRequest(video.streamingPlaylists[0].segmentsSha256Url, HttpStatusCode.OK_200)
 
       await wait(100)
     }
@@ -101,7 +102,7 @@ describe('Fast restream in live', function () {
   before(async function () {
     this.timeout(120000)
 
-    const env = { 'PEERTUBE_TEST_CONSTANTS.VIDEO_LIVE.CLEANUP_DELAY': '10000' }
+    const env = { 'PEERTUBE_TEST_CONSTANTS_VIDEO_LIVE_CLEANUP_DELAY': '10000' }
     server = await createSingleServer(1, {}, { env })
 
     // Get the access tokens