mediacms-io / mediacms

MediaCMS is a modern, fully featured open source video and media CMS, written in Python/Django and React, featuring a REST API.
https://mediacms.io
GNU Affero General Public License v3.0
2.56k stars 468 forks source link

Encoding URL null crashes the frontend if downloads are enabled #882

Closed KyleMaas closed 8 months ago

KyleMaas commented 10 months ago

Describe the issue I've experienced this problem multiple times on multiple video uploads. For best reproducibility, you have to upload a very long video with a huge file size so it takes a while to encode. Otherwise the time period in which this occurs is too short. But when this happens the problem persists for several minutes.

If a video is uploaded and during the encoding process one encoding fails (where, under MediaCMS Administration->Encodings->the relevant encoding, the Status is listed as Fail and there is no encoding file) but the others succeed, and the video has downloads enabled, and you try to view the video in the browser on the frontend before the transcoding process finishes cleaning up faulty encodings, it crashes the frontend. It quickly flashes most of the page up on the screen, starts playing the video, but then the entire screen goes blank. The audio from the video continues playing but the video is hidden along with the rest of the UI, which means you can't pause it or anything else. Relevant information from the media info response:

    "encodings_info": {
        "2160": {},
        "1440": {},
        "1080": {},
        "720": {
            "h264": {
                "title": "h264-720",
                "url": null,
                "progress": 100,
                "size": "",
                "encoding_id": 42461,
                "status": "success"
            }
        },
        "480": {
            "h264": {
                "title": "h264-480",
                "url": "/media/encoded/13/(redacted).mp4",
                "progress": 100,
                "size": "727.1MB",
                "encoding_id": 42161,
                "status": "success"
            }
        },
        "360": {
            "h264": {
                "title": "h264-360",
                "url": "/media/encoded/3/(redacted).mp4",
                "progress": 100,
                "size": "521.1MB",
                "encoding_id": 42061,
                "status": "success"
            }
        },
        "240": {
            "h264": {
                "title": "h264-240",
                "url": "/media/encoded/2/(redacted).mp4",
                "progress": 100,
                "size": "338.6MB",
                "encoding_id": 41761,
                "status": "success"
            }
        }
    },

Digging into the exception on the console, it comes from here:

https://github.com/mediacms-io/mediacms/blob/15d217453bd0d08bb7e3250c6d4b1b5a44e92dcb/frontend/src/static/js/components/media-actions/VideoMediaDownloadLink.jsx#L25

Or, rather, from formatInnerLink's inability to format a first parameter which is null.

To Reproduce Steps to reproduce the issue:

  1. Upload a video where transcoding fails for one encoding but succeeds with the others
  2. Try to view the video's page on the frontend
  3. See error

Expected behavior I would expect that the frontend could somehow cope with the URL of an encoding being null or that only encodings which have succeeded and have a file being passed to the frontend when it requests media information.

Screenshots Can't submit screenshots for this. But when the error manifests, the entire screen is blank white. No UI elements are shown at all other than the browser's built-in interface (address bar, etc.).

Environment (please complete the following information):

Additional context This only really happens right after uploading a video that causes an encoding to fail. For videos which are several hours long, the period you can catch this error in can last several minutes before the faulty encodings are cleaned up.

KyleMaas commented 10 months ago

Actually just ran into this again. Went into MediaCMS Administration, edited the media, disabled downloads, and it pulled up just fine. Encoding is still ongoing, but the video is showing up on the homepage so I'd rather it didn't just crash.

KyleMaas commented 8 months ago

This is an issue I'm seeing on nearly a daily basis now.

mgogoulos commented 8 months ago

Nice description, I've merged this, would be great if you can update and confirm that it is resolved

KyleMaas commented 8 months ago

Same issue here:

https://github.com/mediacms-io/mediacms/blob/dcbfaca91c134e1b1a160d66f7489f3c64d9e3d1/frontend/src/static/js/components/media-actions/MediaMoreOptionsIcon.jsx#L25

Will fix and issue another pull request.

KyleMaas commented 8 months ago

That seems to have fixed it.