FIX: Video uploads sometimes hang indefinitely (#28523)

If there is a codec issue or something trying to process a video file
for thumbnail generation, uploads could hang indefinitely. This fix
  ensures that we continue the upload process even if we encounter an
  error trying to generate a thumbnail for it.
This commit is contained in:
Blake Erickson 2024-08-23 15:58:54 -06:00 committed by GitHub
parent b1a369ab13
commit 274e18622e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 29 additions and 0 deletions

View File

@ -162,5 +162,13 @@ export default class ComposerVideoThumbnailUppy extends EmberObject.extend(
}
}, 100);
};
video.onerror = () => {
// eslint-disable-next-line no-console
console.warn(
"Video could not be loaded or decoded for thumbnail generation"
);
callback();
};
}
}

View File

@ -117,6 +117,27 @@ describe "Uploading files in the composer", type: :system do
end
end
it "handles a video load error gracefully" do
visit "/new-topic"
expect(composer).to be_opened
topic.fill_in_composer_title("Video Load Error Test")
# Inject JavaScript to simulate an invalid video file that triggers onerror
page.execute_script <<-JS
const originalCreateObjectURL = URL.createObjectURL;
URL.createObjectURL = function(blob) {
// Simulate an invalid video source by returning a fake object URL
return 'invalid_video_source.mp4';
};
JS
file_path_1 = file_from_fixtures("small.mp4", "media").path
attach_file(file_path_1) { composer.click_toolbar_button("upload") }
expect(composer).to have_no_in_progress_uploads
expect(composer.preview).to have_css(".onebox-placeholder-container")
end
it "shows video player in composer" do
SiteSetting.enable_diffhtml_preview = true