Bug
In parsePdfFile, page.cleanup() is called on the happy path only. If the async page operation throws, page.cleanup() is never reached and pdfjs internal page resources (font data, operator lists, canvas data) leak for the lifetime of the process.
Affected locations
All three processing modes in src/core.ts:
- MIXED (
processPdfPageTypeMixed throws, e.g. canvas.encode() rejects)
- TEXT (
getTextContent() rejects on a corrupted page stream)
- IMAGE (
processPdfPageTypeImage throws on canvas allocation or render error)
Failure scenario
A 500-page PDF with intermittent render failures — every failing page leaks its pdfjs structures. In a long-running service processing many documents this silently accumulates until memory pressure or OOM.
Fix
Wrap each page task body in try/finally:
limit(async () => {
const page = await pdfDocument.getPage(pageNum);
try {
// ... process page ...
} finally {
page.cleanup();
}
});
Bug
In
parsePdfFile,page.cleanup()is called on the happy path only. If the async page operation throws,page.cleanup()is never reached and pdfjs internal page resources (font data, operator lists, canvas data) leak for the lifetime of the process.Affected locations
All three processing modes in
src/core.ts:processPdfPageTypeMixedthrows, e.g.canvas.encode()rejects)getTextContent()rejects on a corrupted page stream)processPdfPageTypeImagethrows on canvas allocation or render error)Failure scenario
A 500-page PDF with intermittent render failures — every failing page leaks its pdfjs structures. In a long-running service processing many documents this silently accumulates until memory pressure or OOM.
Fix
Wrap each page task body in
try/finally: