fix: continue with live archive processing if ffmpeg task fails#1062
fix: continue with live archive processing if ffmpeg task fails#1062
Conversation
WalkthroughAdds file-existence and non-empty validations for video post-processing and move steps, updates live-download worker finalization behavior, extends task-name mapping for live variants, and adds tests for file validation plus a new (duplicated) live ffmpeg-kill integration test that polls queue task status and kills ffmpeg during tests. Changes
🚥 Pre-merge checks | ✅ 3 | ❌ 3❌ Failed checks (3 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
⚔️ Resolve merge conflicts (beta)
No actionable comments were generated in the recent review. 🎉 🧹 Recent nitpick comments
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
internal/tasks/live_video.go (1)
140-150:⚠️ Potential issue | 🟡 MinorDownload status marked
Successeven on ffmpeg failure—downstream tasks lack pre-checks for missing/empty files.The design allows downstream tasks to run (and fail with errors if the video is missing or invalid), but there are no explicit file existence or size validation checks before
PostProcessVideoorMoveVideoattempt operations. While the system doesn't silently create corrupt archives (both tasks will fail and error out), the resilience relies entirely on implicit error propagation from underlying system calls rather than explicit guards. Consider adding pre-flight validation (e.g.,FileExistschecks) in these workers to fail fast and more gracefully when the download produces no output.
🧹 Nitpick comments (3)
internal/tasks/live_video.go (2)
70-92: Pre-existing goroutine leak: chat-download goroutine can never exit afterctxreassignment.The goroutine at line 72 captures the
ctxvariable by reference. Afterctxis reassigned tocontext.Background()(line 102 or 105),ctx.Done()inside the goroutine becomes a nil channel (never fires). IfstartChatDownloadreceives no further values, the goroutine blocks forever.This existed before for the cancel path and is now extended to the error path. Consider closing the
startChatDownloadchannel after the download call returns, or capturing the original context in a separate variable for the goroutine.Proposed fix: close channel to unblock goroutine
// download live video + // Close startChatDownload after download completes to unblock the goroutine. + defer close(startChatDownload) downloadErr := exec.DownloadTwitchLiveVideo(ctx, dbItems.Video, dbItems.Channel, startChatDownload)Note: this requires updating the goroutine to handle the channel close (a receive on a closed channel returns the zero value immediately). Alternatively, restructure the goroutine to use a dedicated
donechannel.Also applies to: 102-102, 105-105
124-133: Finalization errors after context replacement cause the entire worker to fail — consider whether this is desired.If
getTaskId(line 119) orJobCancel(line 129) fails afterctxhas been replaced withcontext.Background(), the worker returns an error, butMaxAttemptsis 1 (line 29), so there are no retries. This means a transient DB error during finalization could leave the archive stuck despite having a valid video file. This is pre-existing behavior for the cancel path, but now applies more broadly.Consider wrapping these finalization calls with best-effort error handling (log + continue) rather than hard-failing, similar to how
downloadErritself is now treated.internal/live/live_test.go (1)
109-127: Helper name is misleading — it only checksTaskVideoDownload.
waitForQueueTaskStatussounds generic, but line 121 hardcodes the check toq.TaskVideoDownload. If this helper is reused for other task fields, it will silently check the wrong one.Consider renaming to
waitForQueueVideoDownloadStatusor parameterizing the field check.
Fixes #1059