Skip to content

[Enhancement] PDF generation in certificate download has no timeout guard #762

Description

@RUKAYAT-CODER

Overview

src/app/api/certificates/[id]/download/route.ts contains a TODO noting that a timeout should be added for PDF generation. Puppeteer-based PDF generation can hang indefinitely if the target page fails to load or the rendering process deadlocks, leaving the HTTP connection open and consuming a server process slot.

Specifications

Features:

  • PDF generation is bounded by a configurable timeout defaulting to 30 seconds
  • Timed-out requests return HTTP 504 with a retry-friendly error message

Tasks:

  • Wrap the PDF generation call in a Promise.race([generatePDF(...), timeout(30_000)])
  • Return HTTP 504 on timeout with { error: 'PDF generation timed out, please retry' }
  • Set the Puppeteer timeout option: page.setDefaultTimeout(25000)
  • Add an integration test that mocks a slow PDF generation and asserts the 504 response

Impacted Files:

  • src/app/api/certificates/[id]/download/route.ts
  • src/app/api/generate-pdf/route.ts

Acceptance Criteria

  • PDF generation that exceeds 30 seconds returns HTTP 504
  • The connection is closed and the Puppeteer browser is cleaned up on timeout
  • Successful PDF generation under 30 seconds is unaffected

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave programenhancementNew feature or request

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions