]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Fix import video file lock
authorChocobozzz <me@florianbigard.com>
Tue, 2 May 2023 11:38:00 +0000 (13:38 +0200)
committerChocobozzz <chocobozzz@cpy.re>
Tue, 9 May 2023 06:57:34 +0000 (08:57 +0200)
server/lib/job-queue/handlers/transcoding-job-builder.ts
server/lib/job-queue/handlers/video-import.ts
server/lib/job-queue/handlers/video-studio-edition.ts
server/lib/transcoding/create-transcoding-job.ts
server/lib/transcoding/shared/job-builders/abstract-job-builder.ts
server/lib/transcoding/shared/job-builders/transcoding-job-queue-builder.ts
server/lib/transcoding/shared/job-builders/transcoding-runner-job-builder.ts

index cb45337dfe3edd8beb781eb61ab7cc7d2803464a..8621b109fe5da30ff5ab96fbdb632f39e1efa58a 100644 (file)
@@ -23,7 +23,8 @@ async function processTranscodingJobBuilder (job: Job) {
 
       video,
       videoFile,
-      user
+      user,
+      videoFileAlreadyLocked: false
     })
   }
 
index 2a063282cf2aef546c587bc012ff2b75a17488fe..cdd362f6e9391cf1b1272152355ea2fa8386cb8e 100644 (file)
@@ -242,7 +242,7 @@ async function processFile (downloader: () => Promise<string>, videoImport: MVid
         })
       })
 
-      await afterImportSuccess({ videoImport: videoImportUpdated, video, videoFile, user: videoImport.User })
+      await afterImportSuccess({ videoImport: videoImportUpdated, video, videoFile, user: videoImport.User, videoFileAlreadyLocked: true })
     } finally {
       videoFileLockReleaser()
     }
@@ -292,8 +292,9 @@ async function afterImportSuccess (options: {
   video: MVideoFullLight
   videoFile: MVideoFile
   user: MUserId
+  videoFileAlreadyLocked: boolean
 }) {
-  const { video, videoFile, videoImport, user } = options
+  const { video, videoFile, videoImport, user, videoFileAlreadyLocked } = options
 
   Notifier.Instance.notifyOnFinishedVideoImport({ videoImport: Object.assign(videoImport, { Video: video }), success: true })
 
@@ -313,7 +314,7 @@ async function afterImportSuccess (options: {
   }
 
   if (video.state === VideoState.TO_TRANSCODE) { // Create transcoding jobs?
-    await createOptimizeOrMergeAudioJobs({ video, videoFile, isNewVideo: true, user })
+    await createOptimizeOrMergeAudioJobs({ video, videoFile, isNewVideo: true, user, videoFileAlreadyLocked })
   }
 }
 
index 991d11ef153498c7b58d38d132d5e895cec6636d..fbb55a388631f3cb8041049f442f08154ebfb791 100644 (file)
@@ -95,7 +95,7 @@ async function processVideoStudioEdition (job: Job) {
 
   const user = await UserModel.loadByVideoId(video.id)
 
-  await createOptimizeOrMergeAudioJobs({ video, videoFile: newFile, isNewVideo: false, user })
+  await createOptimizeOrMergeAudioJobs({ video, videoFile: newFile, isNewVideo: false, user, videoFileAlreadyLocked: false })
 }
 
 // ---------------------------------------------------------------------------
index 46831a912d0625613268740b17a8840902377208..abe32684de7f8f10d6b4ac6a3288b497a91efed1 100644 (file)
@@ -7,6 +7,7 @@ export function createOptimizeOrMergeAudioJobs (options: {
   videoFile: MVideoFile
   isNewVideo: boolean
   user: MUserId
+  videoFileAlreadyLocked: boolean
 }) {
   return getJobBuilder().createOptimizeOrMergeAudioJobs(options)
 }
index f1e9efdcf362c1b23cc7a9413da6abbb20066fc4..576e786d5122a8fa2a0f3c9f08e62b39fce825ef 100644 (file)
@@ -10,6 +10,7 @@ export abstract class AbstractJobBuilder {
     videoFile: MVideoFile
     isNewVideo: boolean
     user: MUserId
+    videoFileAlreadyLocked: boolean
   }): Promise<any>
 
   abstract createTranscodingJobs (options: {
index c09c6b8ce9b6cfc56deaa86be31b64dbcc4a7b9b..5a9c93ee5271486436c0433fe1d05d5ba8d35611 100644 (file)
@@ -27,13 +27,16 @@ export class TranscodingJobQueueBuilder extends AbstractJobBuilder {
     videoFile: MVideoFile
     isNewVideo: boolean
     user: MUserId
+    videoFileAlreadyLocked: boolean
   }) {
-    const { video, videoFile, isNewVideo, user } = options
+    const { video, videoFile, isNewVideo, user, videoFileAlreadyLocked } = options
 
     let mergeOrOptimizePayload: MergeAudioTranscodingPayload | OptimizeTranscodingPayload
     let nextTranscodingSequentialJobPayloads: (NewWebTorrentResolutionTranscodingPayload | HLSTranscodingPayload)[][] = []
 
-    const mutexReleaser = await VideoPathManager.Instance.lockFiles(video.uuid)
+    const mutexReleaser = videoFileAlreadyLocked
+      ? () => {}
+      : await VideoPathManager.Instance.lockFiles(video.uuid)
 
     try {
       await VideoPathManager.Instance.makeAvailableVideoFile(videoFile.withVideoOrPlaylist(video), async videoFilePath => {
index c7a63d2e2df38082a296632d66ffa1c4b7dd1510..274dce21b74c9163ff00223a5659fba6d39f2138 100644 (file)
@@ -26,10 +26,13 @@ export class TranscodingRunnerJobBuilder extends AbstractJobBuilder {
     videoFile: MVideoFile
     isNewVideo: boolean
     user: MUserId
+    videoFileAlreadyLocked: boolean
   }) {
-    const { video, videoFile, isNewVideo, user } = options
+    const { video, videoFile, isNewVideo, user, videoFileAlreadyLocked } = options
 
-    const mutexReleaser = await VideoPathManager.Instance.lockFiles(video.uuid)
+    const mutexReleaser = videoFileAlreadyLocked
+      ? () => {}
+      : await VideoPathManager.Instance.lockFiles(video.uuid)
 
     try {
       await VideoPathManager.Instance.makeAvailableVideoFile(videoFile.withVideoOrPlaylist(video), async videoFilePath => {