Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VxAdmin: Disable PDF preview/export for large reports #5343

Merged
merged 9 commits into from
Sep 5, 2024

Conversation

jonahkagan
Copy link
Collaborator

@jonahkagan jonahkagan commented Aug 29, 2024

Overview

Fixes: #5278

When report PDFs are very very long (~1000 pages), Chromium will crash when trying to render them. In addition, the frontend PDF preview can crash at ~100 pages.

To prevent this, we set two limits:

  • A limit on the HTML content length that we'll try to render as a PDF
  • A limit on the page length for PDF previews

This PR also fixes two small bugs:

  • Don't render empty reports
  • Reset page count when PDF data changes

Demo Video or Screenshot

Screen.Recording.2024-08-29.at.4.49.19.PM.mov

Testing Plan

To set the limits, I tested a variety of content lengths and chose conservative numbers. I also updated automated tests

Checklist

  • I have added logging where appropriate to any new user actions, system updates such as file reads or storage writes, or errors introduced.
  • I have added a screenshot and/or video to this PR to demo the change
  • I have added the "user_facing_change" label to this PR to automate an announcement in #machine-product-updates

@jonahkagan jonahkagan changed the title VxAdmin: Disable PDF export for large reports VxAdmin: Disable PDF preview/export for large reports Aug 29, 2024
@jonahkagan jonahkagan force-pushed the jonah/disable-large-report-previews branch from 56f307a to cbe3104 Compare August 29, 2024 23:56
@jonahkagan jonahkagan force-pushed the jonah/disable-large-report-previews branch from 8d20bfc to d4567b6 Compare September 3, 2024 23:34
@jonahkagan jonahkagan marked this pull request as ready for review September 3, 2024 23:34
Copy link
Contributor

@carolinemodic carolinemodic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a few places you are added a potential error condition after a "success" log occurs so it would be better to move the log below there and have it log either a "success" or "failure" as appropriate. Otherwise, lgtm.

@@ -88,14 +88,19 @@ export async function generateBallotCountReportPreview({

...reportProps
}: BallotCountReportPreviewProps): Promise<BallotCountReportPreview> {
const report = buildBallotCountReport(reportProps);
await logger.logAsCurrentRole(LogEventId.ElectionReportPreviewed, {
message: `User previewed a ballot count report.`,
disposition: 'success',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible to make this log as a failure if there is an error in getting the report preview?

Copy link
Collaborator Author

@jonahkagan jonahkagan Sep 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good call, thanks 2bdba80

@@ -121,12 +120,18 @@ export async function generateTallyReportPreview({
message: `User previewed a tally report.`,
disposition: 'success',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same logging comment

/**
* Returns a PDF preview of the write-in adjudication report, as a buffer.
*/
export async function generateWriteInAdjudicationReportPreview({
logger,

...reportProps
}: WriteInAdjudicationReportPreviewProps): Promise<Buffer> {
}: WriteInAdjudicationReportPreviewProps): Promise<WriteInAdjudicationReportPreview> {
const report = buildWriteInAdjudicationReport(reportProps);
await logger.logAsCurrentRole(LogEventId.ElectionReportPreviewed, {
message: `User previewed the write-in adjudication report.`,
disposition: 'success',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

failure logging

Chromium crashes with an out of memory error when trying to generate a
PDF for very large documents. Set a limit well below that point to
prevent crashes and return a usable error code.
We'll use the preview error to disable the buttons to print/export PDF
reports, so we don't need to propagate those errors.
At around 100 pages, the browser starts crashing occasionally during
scrolling. To prevent this, set a conservative limit of 50 pages.
Previously, reports with no data showed up as a blank page. Instead, we
don't render them at all.
In the report builder, changing the parameters would remove the current
PDF preview but leave the page count.
We don't expect any of these PDFs to reach the length limit. If they do,
it's an unexpected error, so we can crash explicitly, since that's an
improvement over hanging or crashing with a Chromium error.
@jonahkagan jonahkagan force-pushed the jonah/disable-large-report-previews branch from d4567b6 to 40d199c Compare September 5, 2024 16:52
@jonahkagan jonahkagan force-pushed the jonah/disable-large-report-previews branch from 40d199c to 2bdba80 Compare September 5, 2024 16:53
@jonahkagan jonahkagan enabled auto-merge (squash) September 5, 2024 16:53
@jonahkagan jonahkagan merged commit 619e0c8 into main Sep 5, 2024
62 checks passed
@jonahkagan jonahkagan deleted the jonah/disable-large-report-previews branch September 5, 2024 17:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

VxAdmin: Large tally reports, with lots of groups, fail to generate
2 participants