Skip to content

fix(printing): release ShaperFont owners on partial PDF font setup failures - #4528

Merged
Y-PLONI merged 8 commits into
devfrom
palmoni5/fix-calendar-tikkun-shaper-ownership-20261108
Nov 9, 2026
Merged

Y-PLONI merged 8 commits into
devfrom
palmoni5/fix-calendar-tikkun-shaper-ownership-20261108

Conversation

@palmoni5

@palmoni5 palmoni5 commented Nov 8, 2026

Copy link
Copy Markdown
Member

Problem

Two remaining PDF export paths can retain native font references during partial setup failures, despite the main printing flow being fixed in #4302.

Changes

  • Calendar PDF: use the already-tested withShaperFontPair scope to guarantee the primary owner is released if fallback registration fails and both are released after asynchronous pdf.save() completes, including exceptions.
  • Tikkun PDF: roll back ShaperFont.register() if _ExportFont/PdfShapedFont construction fails, before the font can enter _fonts and its normal finally cleanup.

No changes to native Rust, ABI, text layout, or successful PDF bytes are intended.

QA / merge gate

  • Review diff for ownership and save ordering.
  • Run flutter analyze and existing calendar/Tikkun/PDF tests in GitHub Actions.
  • Check test failures and CI before merge.
  • Do not treat CI as an independent human/agent code review.

Related: Otzaria/opentype_shaper#4, #4302.

palmoni5 commented Nov 8, 2026

Copy link
Copy Markdown
Member Author

QA status for head 00fe5dd4c58630433f308a223c7c1d1dd3bc8fa3 (CI run):

  • flutter analyze passed.
  • All five Linux test shards (0–4) passed.
  • Windows build passed.
  • Windows tests were blocked while fetching the unrelated sqlite3 native DLL: downloaded SHA256 8e8052a0… did not match the package-expected 3a29878d… (Build assets for package:sqlite3 failed). This occurred before code tests could run.
  • Linux build failed at Download prebuilt WPE runtime SDK (curl exit code 18), unrelated to the two modified PDF source files.

The changes are confined to font-owner cleanup on partial setup failures. These CI infrastructure issues are not represented as passing checks. Leave this PR open; no merge to Otzaria has been requested.

palmoni5 commented Nov 8, 2026

Copy link
Copy Markdown
Member Author

Ownership regression QA — head 79744a743f13fbda19e5d55a409cde8d71fc5d82

Follow-up implementation/tests were pushed to this PR branch using palmoni5. No merge was performed.

Fault paths exercised

  • Calendar PDF: withShaperFontPair keeps both font owners alive through the awaited pdf.save(), releases fallback before primary, and releases primary if fallback registration fails. Three successful real Calendar exports verify both distinct native handles have zero residual registry references after cleanup.
  • Partial registration: a malformed but parseable SFNT registers natively, then fails during Dart ShaperFont construction; the test verifies the fallback's transient native reference is rolled back and the primary is released. The pinned opentype_shaper implementation already contains the rollback from package PR Add PDF search result count #4; a dependency bump was not required.
  • Tikkun PDF: injectable PDF-font builder and saver retain the original defaults but allow deterministic error injection. Tests verify failure constructing the first and second PdfShapedFont (including a previously cached font), asynchronous save failure after the writer enters save, cancellation after loading/registering a font, and eight repeated successful exports. The existing writer's finally releases cached owners even when save/cancellation throws.
  • Double-dispose / refcounts: 16 repeated asynchronous failure cycles, including already-disposed owners, confirm idempotent cleanup. Every new lifecycle test checks the native registry using ShaperBindings.releaseFont; unknownHandle after owner disposal confirms no retained registry entry/associated font allocation. This is a native reference-allocation check, not a process-wide RSS/heap measurement.

Successful-output invariants

The default Tikkun factory still constructs PdfShapedFont with the same arguments and extraction callback, and the saver still calls PdfDocument.save(enableEventLoopBalancing: true). Calendar page construction and save are unchanged inside the new resource scope. Existing Calendar and Tikkun vector-PDF/content tests passed. No byte-for-byte golden comparison against the pre-PR artifacts was run, so this is code-path equivalence and output-regression coverage, not a separately measured binary-equivalence claim.

CI evidence

Flutter Tests run #6040, for the exact head above, completed successfully:

  • Flutter Analyze: success.
  • All 5 Linux test shards: success, 25,501 passed / 149 skipped. Logs explicitly report all new Calendar, Tikkun and shaper-scope ownership tests passing.
  • Windows Tests: success, 3,019 passed / 7 skipped.
  • Windows Build (including integration and multiview smoke): success.
  • Linux Build (including engine SQLite integration): success.
  • Lockfile Guard: success (separately; not used as a substitute for Flutter Tests).

For context, the older run #42477550622 had unrelated infrastructure failures (sqlite3 Windows DLL SHA-256 mismatch and Linux WPE download curl code 18). Both jobs passed in the new run, and those old failures are not classified as application test failures.

A separate source-level second-pass review of the cleanup order and ownership transfer found no missing release path. This review and CI are not presented as an independent external human/agent approval; no such reviewer has signed off on the PR.

Leave PR open; do not merge without explicit authorization.

@Y-PLONI
Y-PLONI force-pushed the palmoni5/fix-calendar-tikkun-shaper-ownership-20261108 branch from 79744a7 to 2b50a59 Compare November 9, 2026 12:13
@Y-PLONI
Y-PLONI merged commit cfefccb into dev Nov 9, 2026
12 checks passed
@Y-PLONI
Y-PLONI deleted the palmoni5/fix-calendar-tikkun-shaper-ownership-20261108 branch November 9, 2026 12:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants