Fix concurrent namespace load error attribution - #9677
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This pull request fixes a race in ITwinLocalization.registerNamespace where i18next can report queue-wide errors from other concurrent namespace loads, causing a successfully loaded namespace to be incorrectly logged as unavailable. The fix determines load success by checking i18next’s resource store for the requested namespace across the active language resolution list, and adds a deterministic unit test covering the “failure completes first” concurrency case.
Changes:
- Replace error-attribution logic in
registerNamespacewith a resource-store check viai18next.hasResourceBundle(...)for active/fallback languages. - Add a unit test that concurrently registers a successful and failing namespace and asserts only the failing namespace is logged.
- Add a Rush change file documenting the behavior fix for
@itwin/core-i18n.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| core/i18n/src/ITwinLocalization.ts | Updates namespace-load failure attribution to rely on resource-store presence instead of parsing callback error contents. |
| core/i18n/src/test/ITwinLocalization.test.ts | Adds deterministic coverage for concurrent namespace registration where the failing load completes first. |
| common/changes/@itwin/core-i18n/jason-crow-fix-concurrent-namespace-errors_2026-08-31-17-20.json | Records the fix as a no-version-change Rush change entry for @itwin/core-i18n. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
🟡 Changes recommended
The new regression test deadlocks by awaiting the failed load before completing the successful pending load.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
- Files reviewed: 3/3 changed files
- Comments generated: 1
- Review effort level: Balanced
|
I fixed up the lint errors that were blocking the pipeline. Other than the issues commented on, LGTM |
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Summary
Reviewer Q&A
Is removing the
try/catchcompletely safe?It is safe under
ITwinLocalization's existing initialized-use contract. The removedtry/catchonly handlederrbeing non-iterable. The replacement does not read or iterateerr; it uses i18next's stablehasResourceBundle()API. Also,getLanguageList().map(...)was already outside the oldtry, so uninitialized usage was never protected by it.An unexpected exception inside i18next would indicate corrupted or uninitialized state rather than a normal namespace-load error. Removing this catch therefore does not hide or newly expose an expected error path.
What was
thisLocalefor, and why is it safe to remove its role?thisLocalerepresented each active or fallback language, such asfr-CA,fr, oren. The old implementation searched error strings for/<locale>/and inferred whether all locale attempts failed. That inference is unsafe during concurrent loads because the callback can contain an error for another namespace in the same locale.The replacement does not remove locales from the decision. It checks the requested namespace together with every active or fallback language:
i18next adds successful resources to its store before invoking the load callback, so this directly answers the intended question: did this namespace load for any applicable locale? It is more precise than parsing error-message text because both the locale and requested namespace participate in the check.
Validation
git diff --check— passedrushx build— blocked because the incomplete Rush dependency install left TypeScript files unavailablerushx lint— blocked because the incomplete Rush dependency install left ESLint unavailablerushx test— blocked because the incomplete Rush dependency install left a test-runner dependency unavailablerush install— retried, but the local pnpm store failed withERR_PNPM_ENOENTwhile materializing workspace packagesFixes #9676