Skip to content

fix: Synchronize ResourceLoader table rebuilds (fixes #26636) - #26690

Open
seragAhmed wants to merge 1 commit into
unoplatform:masterfrom
seragAhmed:fix/26636-resourceloader-thread-safety
Open

seragAhmed wants to merge 1 commit into
unoplatform:masterfrom
seragAhmed:fix/26636-resourceloader-thread-safety

Conversation

@seragAhmed

Copy link
Copy Markdown
Contributor

GitHub Issue: closes #26636

PR Type:

🐞 Bugfix

What changed? 🚀

When two threads made the first ResourceLoader.GetString call after a language change at the same time, both rebuilt the shared resource tables, which could throw the reported NullReferenceException in ProcessResourceFile or leave the tables half-populated.

Validation

  • Unit test Given_ResourceLoader.When_Concurrent_First_Lookups_After_Language_Change: on master it fails with the reported NullReferenceException at ProcessResourceFile (or a "concurrent update" InvalidOperationException); with the fix it passes reliably. All 42 ResourceLoader unit tests pass.
  • Every GetString now takes the lock; an uncontended lock is cheap, but a lock-free snapshot swap is possible if preferred.

PR Checklist ✅

  • 🧪 Added unit tests
  • 📚 Docs
  • 🖼️ Validated PR Screenshots Compare Test Run results.
  • ❗ Contains NO breaking changes

The first GetString after a language change rebuilds the shared resource
tables in place, with no synchronization. Two threads making that first
lookup at once could both rebuild them, so one read a culture entry the
other had added but not yet filled (NullReferenceException in
ProcessResourceFile) or corrupted the dictionaries. Guard the lookups,
the rebuild and the other static table mutations with one lock.
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
1 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@github-actions github-actions Bot added the area/automation Categorizes an issue or PR as relevant to project automation label Nov 24, 2026
@mergify

mergify Bot commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue). If it does not match the queue conditions yet, it enters the queue once it does.

  • Queue this pull request once it meets the queue conditions

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

Labels

area/automation Categorizes an issue or PR as relevant to project automation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ResourceLoader can throw NullReferenceException in ProcessResourceFile on the first lookup after PrimaryLanguageOverride changes

1 participant