Repository navigation
fix(pdf): serialize PDFium rendering across parser instances - #5952
Merged
Merged
Conversation
Guard PDFium rendering with a shared thread lock to respect its process-wide thread-safety constraint. Extend the existing PNG extraction test to cover concurrent parser instances. Related to #5879.
zhoujh01
approved these changes
Oct 12, 2026
q2000s
pushed a commit
to q2000s/OpenViking
that referenced
this pull request
Oct 12, 2026
main advanced 510 commits while this branch was stacked on volcengine#4725. Resolved a single import-order conflict in pdf.py (main added \ hreading\ for the PDFium render lock in volcengine#5952; this branch added \ empfile\), keeping both. No behavioural change from the resolution.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Concurrent local PDF imports can call PDFium from multiple threads, even though PDFium is not thread-safe across documents.
For example, when two PDFs each contain an image, both imports previously could enter PDFium rendering at the same time. With this change, the image renders run serially under one shared lock, and each import still receives its PNG output.
Human Involvement
Related Issue
Related to #5879; addresses the unsafe PDFium concurrency path only.
Type of Change
Changes Made
pdfplumber.to_image()with a module-levelthreading.Lockshared across parser instances. This call covers PDFium document opening, rendering, and closing.Testing
Updated one existing test; no new test cases or test files were added. The updated test fails without the lock and passes with it.
python -m pytest tests/parse/test_pdf_bookmark_extraction.py -q --no-cov --disable-warnings: 21 passed.ruff check openviking/parse/parsers/pdf.py tests/parse/test_pdf_bookmark_extraction.py: passed.ruff format --check openviking/parse/parsers/pdf.py tests/parse/test_pdf_bookmark_extraction.py: passed.git diff --check: passed.Checklist
Screenshots (if applicable)
Not applicable.
Additional Notes
This change does not alter queue replay behavior or provide process-level crash containment. The original Windows native crash in #5879 has not been reproduced locally; the regression test verifies serialization across parser instances.