Repository navigation
fix(resources): make AddLookupAssembly transactional on parse failure (backport #23960) - #25971
mergify[bot] wants to merge 5 commits into
Conversation
- parse a newly registered assembly's .upri files into temporary dictionaries and merge into the live loaders only after every file parsed successfully (same temp-then-apply pattern as RebuildLoaderResourcesFromSurvivors) - when the failing registration went through the full reload path, re-derive the merged values and parsed markers from the surviving registrations so a truncated .upri's partially parsed pairs cannot remain observable after the rollback - drop the now-dead live marker rollback (a failing parse no longer writes markers into the live set) - add red/green regression tests covering both AddLookupAssembly parse branches with a .upri that declares two pairs and truncates after the first Fixes #23959 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> (cherry picked from commit e47e138)
…actional parse Review follow-up on the transactional `AddLookupAssembly` fix. - Extract `TransactionalParse` (temp dictionaries + marker set + resolver + merge/replace apply) and route `AddLookupAssembly`, `ReloadResources` and `RebuildLoaderResourcesFromSurvivors` through it, replacing three hand-rolled copies of the temp-then-apply pattern. - `ReloadResources` is now transactional too, so the culture-change path via `EnsureLoadersCultures` no longer leaks partial state; the `liveLoadersTouched` control flag and the rebuild-on-failure recovery in the catch are both gone. - Log the rollback before rethrowing (gated on `LogLevel.Error`), naming the assembly and whether the whole cache was being reloaded. - Restate a `.upri` truncated mid key/value pair as `InvalidDataException` naming the file, matching every other malformed-`.upri` case, instead of surfacing `BinaryReader`'s context-free `EndOfStreamException`. - Hand the parsed dictionary over on a `TryGetValue` miss instead of allocating an empty one and copying every pair. - Document the language-preference narrowing `RebuildLoaderResourcesFromSurvivors` applies when `PreserveParsedResources` is enabled. - Tests: add `[Description]` + `[GitHubWorkItem]`, assert the documented exception type, assert the truncated loader instance is never created, and replace the private-field reflection helper with the `TryGetMergedResourceForTests` / `ContainsNamedLoader` internal seams. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> (cherry picked from commit a44268e) # Conflicts: # src/Uno.WinRT/ApplicationModel/Resources/ResourceLoader.static.cs
- Move the resource-count read inside the try that restates EndOfStreamException as the documented InvalidDataException, so a stream ending at the count is named like every other truncation point instead of leaking BinaryReader's context-free exception. - Keep the declared count in the message when it was read, and say so explicitly when the truncation preceded it. - Add a red/green regression test for a .upri truncated before its count (fails with EndOfStreamException on the previous code). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> (cherry picked from commit 4488087) # Conflicts: # src/Uno.WinRT/ApplicationModel/Resources/ResourceLoader.static.cs
- give each survivor in RebuildLoaderResourcesFromSurvivors its own scratch TransactionalParse, folded into the aggregate only once its Parse returned - the shared parse let a survivor add a marker and its first key/value pair before throwing on a later pair; the guard caught, the loop continued, and the apply phase published the rejected survivor's partial state - roll values AND markers back together: a leaked marker makes a later parse skip a file it should have read - factor the temp-to-live merge loop into MergeInto so the new temp-to-temp fold reuses the same last-writer-wins-per-key semantics - add the truncated-after-first-pair rebuild regression, plus the counterpart assertion that a good survivor's values are still published Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> (cherry picked from commit 09ad807) # Conflicts: # src/Uno.UWP/ApplicationModel/Resources/ResourceLoader.static.cs
|
Cherry-pick of a44268e has failed: Cherry-pick of 4488087 has failed: Cherry-pick of 09ad807 has failed: To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally |
The backport recreated ResourceLoader.static.cs under the removed Uno.UWP folder and deleted the live Uno.WinRT copy; move it back. Port the transactional-parse changes onto master's Uno.WinRT file, keeping its UPRI v3 parser, and reject an unreadable stream or an out-of-range name length as InvalidDataException. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Nick Randolph seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
|
🤖 Your WebAssembly Sample App stage site is ready! Visit it here: |
|
The build 243134 found UI Test snapshots differences: Details
|
|
Tick the box to add this pull request to the merge queue (same as
|
GitHub Issue: closes #23959
PR Type:
🐞 Bugfix
What changed? 🚀
Follow-up to #23707.
AddLookupAssemblyrolled back the_lookupAssembliesregistration and parsed-resource markers when parsing threw, butProcessResourceFilemerges each key/value pair straight into the live loader dictionaries as it reads. A.upriwith a valid header that declares two pairs, carries one complete pair, then truncates fails on the second pair — after the rollback, the unregistered assembly's first pair remained observable throughGetString(permanently, when the loader context was already established, since no later lookup reloads).Every path that mutates the live loader state now goes through a single transactional parse.
TransactionalParse(new private nested type) owns the temp dictionaries, the temp marker set, the loader resolver, and the two apply phases (MergeIntoLiveLoaders,ReplaceLiveLoaders). It replaces the three hand-rolled copies of the temp-then-apply pattern the file had grown.AddLookupAssembly— single-assembly branch (changed loader context):ProcessAssemblyTransactionallyparses into temporaries with the marker set seeded from the assembly's already-parsed markers, so skip semantics are unchanged, and merges only after every file parsed successfully.AddLookupAssembly— full-reload branch:ReloadResourcesis itself transactional now, so the failure never touches the live state. That also makes the culture-change path (EnsureLoadersCultures→ReloadResources) transactional, which the earlier revision did not cover.liveLoadersTouchedcontrol flag, theRebuildLoaderResourcesFromSurvivors()recovery call in the catch, and the live-marker rollback (_parsedResources.RemoveWhere) are all gone: removing the list entry is the whole rollback.RebuildLoaderResourcesFromSurvivorskeeps its per-assembly guard and is still used by the ALC sweep.ClearResources()and the two-argumentProcessAssemblyoverload became unused and were removed._log.IsEnabled(LogLevel.Error)), reporting the assembly whose registration was rolled back and whether the whole cache was being reloaded — in that branch the faulting.uprican belong to a pre-existing registration rather than to the assembly being rolled back..upritruncated in the middle of its declared pairs surfacedBinaryReader's context-freeEndOfStreamException.ProcessResourceFilenow restates it asInvalidDataException($"Truncated resource file {fileName}: …", error), matching what it already does (and documents) for every other malformed-.upricase.InvalidDataExceptionis already in the rebuild guard's filter, so recovery semantics are unchanged.TryGetValuemiss instead of allocating an empty dictionary and copying every pair — the zero-copy ownership transferRebuildLoaderResourcesFromSurvivorsalready used.RebuildLoaderResourcesFromSurvivorsre-derives values only for the last established context's language preferences, so withPreserveParsedResourcesenabled it drops values preserved for other cultures (they are re-parsed the next time those languages become active). That is now stated in its XML docs.The
HasContextChangedSignificantlybranch selection inAddLookupAssemblyis unchanged; the two comments describing those branches were swapped and are now accurate.Red/green regression tests
Two new tests in
Given_ResourceLoader_Alcemit (in memory, viaManagedPEBuilder) an assembly embedding a.upriwith valid magic/version/name/culture,resourceCount = 2, one complete pair, truncated before the second pair. Both carry[Description]and[GitHubWorkItem]:When_AddLookupAssembly_Truncated_Upri_Then_Throws_And_Partial_Value_Not_Observable— established loader context (full-reload branch): assertsAddLookupAssemblythrowsInvalidDataException,ContainsLookupAssemblyis false, the truncated.upri's loader instance was never created, the first pair's value is not returned byGetString, and surviving registrations still resolve.When_AddLookupAssembly_Truncated_Upri_With_Changed_Context_Then_Live_Loaders_Untouched— changed loader context (single-assembly branch): asserts the throw, the rollback, that the loader instance was never created (absence, not emptiness, so a regression to the full-reload branch cannot keep the test green), and that no value reached the live loaders.Live state is observed through two new
internaltest seams next toContainsLookupAssembly—TryGetMergedResourceForTestsandContainsNamedLoader— replacing the private-field reflection helper the earlier revision used.GetStringcannot be used for these assertions: it re-establishes the loader context and would reload (and wipe) the loaders, masking the leak.Both tests fail on the pre-fix code with the leaked
TruncatedValueobservable in both branches, and on the loader-instance assertions, and pass with the fix. FullGiven_ResourceLoader_Alc(8 tests) andGiven_AlcCacheSweep(4 tests) pass; the fullUno.UI.UnitTestsrun is 4074 total / 12 failed, and those 12When_Gregorian_FixedDate*failures reproduce identically on the unmodified merge commit2fc0049a256(4072 total / same 12) — environment-dependent, unrelated.PR Checklist ✅
Screenshots Compare Test Runresults.🤖 Generated with Claude Code
This is an automatic backport of pull request #23960 done by [Mergify](https://mergify.com).