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
Overview
src/app/api/certificates/[id]/download/route.tscontains 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:
Tasks:
Promise.race([generatePDF(...), timeout(30_000)]){ error: 'PDF generation timed out, please retry' }timeoutoption:page.setDefaultTimeout(25000)Impacted Files:
src/app/api/certificates/[id]/download/route.tssrc/app/api/generate-pdf/route.tsAcceptance Criteria