Bug
When one page task throws during concurrent processing, Promise.all() rejects and the finally block calls pdfDocument.destroy(). However, other in-flight limit() tasks that were already executing continue running and subsequently call pdfDocument.getPage() or page.render() on the now-destroyed document.
Affected code
src/core.ts — parsePdfFile, all three processing modes (MIXED, TEXT, IMAGE).
Failure scenario
concurrency=4, 10 pages — page 2 throws. Promise.all() rejects; pdfDocument.destroy() is called in the finally block. Pages 3–5 are still mid-flight and call pdfDocument.getPage() or page.render() on the destroyed document, producing crashes or silent data corruption.
Notes
Pre-existing bug (not introduced by any recent change). Neither the old p-limit package nor the current inline implementation provides task cancellation — the fix needs to be at the parsePdfFile level (e.g. an AbortController-style flag checked before each page operation, or Promise.allSettled + post-hoc error aggregation).
Bug
When one page task throws during concurrent processing,
Promise.all()rejects and thefinallyblock callspdfDocument.destroy(). However, other in-flightlimit()tasks that were already executing continue running and subsequently callpdfDocument.getPage()orpage.render()on the now-destroyed document.Affected code
src/core.ts—parsePdfFile, all three processing modes (MIXED, TEXT, IMAGE).Failure scenario
concurrency=4, 10 pages — page 2 throws.Promise.all()rejects;pdfDocument.destroy()is called in thefinallyblock. Pages 3–5 are still mid-flight and callpdfDocument.getPage()orpage.render()on the destroyed document, producing crashes or silent data corruption.Notes
Pre-existing bug (not introduced by any recent change). Neither the old
p-limitpackage nor the current inline implementation provides task cancellation — the fix needs to be at theparsePdfFilelevel (e.g. anAbortController-style flag checked before each page operation, orPromise.allSettled+ post-hoc error aggregation).