Skip to content

bug: in-flight page tasks run against destroyed pdfDocument when one page fails #205

Description

@l2ysho

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.tsparsePdfFile, 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).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions