Repository navigation
ci: pre-initialize fontconfig to fix Pango threaded-FcInit crash in smoke tests - #323015
Merged
Merged
Conversation
…moke tests
Symbolizing the intermittent Electron-startup SIGSEGV crash dumps (Ubuntu debug
symbols + frame-pointer walk) shows the fault is an upstream Pango concurrency
bug, not a VS Code bug:
pango: fc_thread_func -> init_in_thread -> FcInit() (pangofc-fontmap.c)
fontconfig: FcInit -> FcConfigParseAndLoadFromMemory -> _FcConfigParse
libexpat: XML_ParseBuffer -> libc (NULL deref, SIGSEGV)
Pango >= 1.52's pango_fc_font_map_init() unconditionally spawns a
"[pango] fontconfig" thread that runs FcInit(); that races with the
Electron/Chromium main thread's own fontconfig use during startup and corrupts
fontconfig's global config while it is being parsed. The threaded design is a
known-bad area upstream (pango#784 "single fontconfig thread introduces a hang
... seems to be due to a race condition", pango#872), and there is no env var to
disable it (still present in Pango 1.56).
It only manifests in our CI because the race window is microscopic: it needs a
cold process, two threads hitting first-time FcInit() simultaneously, and a slow
machine. Our smoke job is a near-perfect trigger — fresh contended runners, a
wiped fontconfig cache + custom FONTCONFIG_FILE (so FcInit re-parses cold), and
~25 cold Electron starts per run. (This also explains why the expat version was
irrelevant and why dropping the config DOCTYPE made it worse: it is pure timing,
not parser/content.)
Fix: initialize fontconfig once, single-threaded, from an ELF constructor that
runs before main() (and thus before any thread exists), via a tiny LD_PRELOAD
shim. Pango's later threaded FcInit() then finds fontconfig already initialized
and returns immediately, so the concurrent parse never happens and the race is
eliminated.
Co-authored-by: Copilot <[email protected]>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the Linux PR workflow to mitigate intermittent Electron smoke-test startup crashes attributed to a fontconfig initialization race triggered by Pango’s background FcInit() thread. It does so by building a small LD_PRELOAD shim that calls FcInit() from an ELF constructor before main(), and adds diagnostics to confirm the preload is active.
Changes:
- Add a workflow step that compiles a small
LD_PRELOADshared library to pre-initialize fontconfig before Electron/Chromium startup. - Export
LD_PRELOADvia$GITHUB_ENVso subsequent steps inherit the preload. - Extend the existing fontconfig diagnostics step to print and verify the preload configuration.
Show a summary per file
| File | Description |
|---|---|
| .github/workflows/pr-linux-test.yml | Adds an LD_PRELOAD-based fontconfig pre-init shim build step and corresponding diagnostics to reduce Electron startup SIGSEGV flakiness on Linux CI. |
Copilot's findings
- Files reviewed: 1/1 changed files
- Comments generated: 2
Alexandru Dima (alexdima)
marked this pull request as draft
June 25, 2026 21:29
Alexandru Dima (alexdima)
marked this pull request as ready for review
June 25, 2026 22:08
Alexandru Dima (alexdima)
enabled auto-merge (squash)
June 25, 2026 22:09
Raymond Zhao (rzhao271)
approved these changes
Jun 25, 2026
Contributor
Screenshot ChangesBase: Added (354) |
Collaborator
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
The real root cause (symbolized, with corroborating upstream reports)
The intermittent Linux
Electron-SmokeSIGSEGV is an upstream Pango concurrency bug, not a VS Code bug. I pulled the crash dumps, downloaded the matching Ubuntu debug symbols, and resolved the exact frames:Pango ≥ 1.52's
pango_fc_font_map_init()unconditionally spawns a[pango] fontconfigthread that runsFcInit(). That races with the Electron/Chromium main thread's own fontconfig use during startup and corrupts fontconfig's global config mid-parse. There's no env var to disable it (still present in Pango 1.56).This is a known-bad area upstream:
stracemakes the problem disappear. So this seems to be due to a race condition."Why it shows up in our CI and not "all over the internet"
It's a microsecond-wide race in first-time
FcInit. To hit it you need a cold process, two threads reaching first-timeFcInit()at the same instant, and a slow machine. Desktop apps have warm fontconfig state, fast cores, and launch once — they never land in the window. Our smoke job is a near-perfect trigger: fresh contended 4‑vCPU runners, a wiped fontconfig cache + customFONTCONFIG_FILE(soFcInitre-parses cold and slow = wider window), and ~25 cold Electron starts per run. That turns "never" into ~1%/launch, which compounds to the 8–19% per-run failure.This also resolves the two facts that broke earlier theories: the expat version was irrelevant (it's the concurrent parse, not the parser — installing 2.8.1 still crashed identically), and dropping the config DOCTYPE made it worse (pure timing, not content).
The fix
Initialize fontconfig once, single-threaded, from an ELF constructor that runs before
main()(and therefore before any thread exists), via a tinyLD_PRELOADshim:Pango's later threaded
FcInit()then finds fontconfig already initialized and returns immediately — the concurrent parse never happens, so the race is eliminated. It's ~12 lines, needs onlygcc+-ldl(both present), and auto-applies to every Electron/Chromium launch in the job.Validation
-Wall -Wextra).LD_PRELOADso the preload is verifiable from CI logs.Supersedes
Co-authored-by: Copilot [email protected]