Skip to content

fix: initialize the system FontConfig before GTK starts on Linux - #53314

Merged
MarshallOfSound merged 2 commits into
mainfrom
fix/linux-fontconfig-preinit
Aug 31, 2026
Merged

MarshallOfSound merged 2 commits into
mainfrom
fix/linux-fontconfig-preinit

Conversation

@MarshallOfSound

@MarshallOfSound MarshallOfSound commented Aug 30, 2026 •

Copy link
Copy Markdown
Member

Description of Change

Fixes #53200

  • Pango 1.52+ spawns a [pango] fontconfig thread that calls FcInit() as soon as GTK creates its font map, and that races the main thread's own first fontconfig call during toolkit initialization. Both parse the configuration at once and corrupt fontconfig's global state; it later surfaces as a PartitionAlloc freelist check (SIGTRAP, [Bug]: Electron 44.0.0 Linux SIGTRAP: PartitionAlloc freelist corruption detected during Fontconfig startup #53200) or a NULL dereference inside expat (Smoke test Electron crash (SIGSEGV) on relaunch — fontconfig/expat font init in browser process microsoft/vscode#322185). Upstream: pango#784, pango#872.
  • Initialize the system fontconfig once on a helper thread that runs while the Node.js environment is created and is joined before any app code runs, so both later FcInit() calls return immediately. Nothing else touches fontconfig or calls setenv during that window. Resolved via dlsym because the binary also contains Chromium's bundled fontconfig with hidden visibility, which is a separate copy with separate state (that is also why gfx::GetGlobalFontConfig() in gtk_ui.cc does not prevent this).
  • If the app's main script changed FONTCONFIG_FILE, FONTCONFIG_PATH or FONTCONFIG_SYSROOT, reload the configuration after the join so GTK still sees what the app asked for.

Main-thread cost, measured with a temporary log around the join (Testing build, Xvfb, warm cache, 8 launches):

median
helper thread FcInit() 3.8 ms (off main thread)
main thread wait at the join 27 µs
reload when the app changed the env 3.6 ms (only in that case)

Checklist

Release Notes

Notes: Fixed an intermittent crash at startup on Linux caused by a race between Pango and the main thread initializing fontconfig.

@MarshallOfSound MarshallOfSound added semver/patch backwards-compatible bug fixes target/43-x-y PR should also be added to the "43-x-y" branch. target/44-x-y PR should also be added to the "44-x-y" branch. target/45-x-y PR should also be added to the "45-x-y" branch. labels Aug 30, 2026
@electron-cation electron-cation Bot added the new-pr 🌱 PR opened recently label Aug 30, 2026
@MarshallOfSound
MarshallOfSound force-pushed the fix/linux-fontconfig-preinit branch from 1e4f97b to 283b682 Compare August 30, 2026 08:06
Pango >= 1.52 spawns a thread that calls FcInit() as soon as GTK creates its
font map. That races the main thread's own first FontConfig call during
toolkit initialization: both parse the configuration at once and corrupt
FontConfig's global state, which later surfaces as a PartitionAlloc freelist
corruption check (SIGTRAP) or a NULL dereference inside expat.

Initialize the system FontConfig library once, on a helper thread that runs
while the Node.js environment is created and is joined before any app code
runs, so both later FcInit() calls are no-ops. The symbol is resolved with
dlsym because the executable also contains Chromium's bundled FontConfig with
hidden visibility. If the app's main script changed the FontConfig
environment variables, the configuration is reloaded so GTK sees them.
@MarshallOfSound
MarshallOfSound force-pushed the fix/linux-fontconfig-preinit branch from 283b682 to ca56ef3 Compare August 30, 2026 08:30
@electron-cation electron-cation Bot removed the new-pr 🌱 PR opened recently label Aug 31, 2026

@deepak1556 deepak1556 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ckerr ckerr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice find, thanks for tracking this down 👍

@MarshallOfSound
MarshallOfSound enabled auto-merge (squash) August 31, 2026 15:49
@MarshallOfSound
MarshallOfSound merged commit fc686ea into main Aug 31, 2026
74 of 77 checks passed
@MarshallOfSound
MarshallOfSound deleted the fix/linux-fontconfig-preinit branch August 31, 2026 17:47
@release-clerk

release-clerk Bot commented Aug 31, 2026

Copy link
Copy Markdown

Release Notes Persisted

Fixed an intermittent crash at startup on Linux caused by a race between Pango and the main thread initializing fontconfig.

@trop

trop Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

I have automatically backported this PR to "45-x-y", please check out #53338

@trop trop Bot added in-flight/45-x-y and removed target/45-x-y PR should also be added to the "45-x-y" branch. labels Aug 31, 2026
@trop

trop Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

I have automatically backported this PR to "43-x-y", please check out #53339

@trop

trop Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

I have automatically backported this PR to "44-x-y", please check out #53340

@trop trop Bot added in-flight/43-x-y in-flight/44-x-y and removed target/43-x-y PR should also be added to the "43-x-y" branch. labels Aug 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

46-x-y merged/43-x-y PR was merged to the "43-x-y" branch. merged/44-x-y PR was merged to the "44-x-y" branch. merged/45-x-y PR was merged to the "45-x-y" branch. platform/linux semver/patch backwards-compatible bug fixes

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

[Bug]: Electron 44.0.0 Linux SIGTRAP: PartitionAlloc freelist corruption detected during Fontconfig startup

3 participants