Skip to content

Loader: summaries take a snapshot of their concurrent dictionaries before LINQ - #22

Open
Sr-0w wants to merge 1 commit into
ThatRecompDev:mainfrom
Sr-0w:loader/summary-snapshots
Open

Sr-0w wants to merge 1 commit into
ThatRecompDev:mainfrom
Sr-0w:loader/summary-snapshots

Conversation

@Sr-0w

@Sr-0w Sr-0w commented Nov 25, 2026

Copy link
Copy Markdown

What changed

StandInPipelines.SkippedBeforeSummary and OnDemandPrograms.Summary take a snapshot with ConcurrentDictionary.ToArray() before summing and sorting, instead of running LINQ over the dictionary itself.

Why

Enumerable.ToArray over an ICollection sizes its array by Count and then calls CopyTo. If another thread adds an entry in between, CopyTo throws ArgumentException. Both dictionaries are written by build threads and command lists while the sampler thread reads them. With --sample-threads 30, a boot on an RX 7800 XT ended at 4,200 presents with 0xE0434352:

Unhandled exception. System.ArgumentException: The index is equal to or greater than the length of the array, or the number of elements in the dictionary is greater than the available space from index to the end of the destination
   at System.Collections.Concurrent.ConcurrentDictionary`2...CopyTo(KeyValuePair`2[] array, Int32 index)
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
   ...
   at FiveStar.Loader.Shims.D3D12X.Pipelines.StandInPipelines.SkippedBeforeSummary() StandInPipelines.cs:line 436
   at FiveStar.Loader.Shims.D3D12X.Pipelines.StandInPipelines.get_Summary()
   at FiveStar.Loader.Shims.D3D12X.Pipelines.PipelineSlots.get_Summary()
   at FiveStar.Loader.Host.LoaderHost.SampledCounters()
   at FiveStar.Loader.Diagnostics.ThreadSampler.Run(TimeSpan interval)

ConcurrentDictionary.ToArray takes the entries under the dictionary's locks. OnDemandPrograms.Summary had the same pattern over _failures.

How I checked

  • dotnet build: no errors or warnings. FiveStar.Architecture.Tests passes (30 tests).
  • FiveStar.Loader.Tests: 207 passed, 18 skipped, 1 failed. The failure is CompileBudgetTests.A_compile_starts_only_while_memory_covers_it_what_the_running_ones_still_need_and_the_games_growth, which fails the same way on main (72b7328) on this machine; it reads the machine's free memory.
  • No new test: the race needs a writer between Count and CopyTo, which a unit test would only hit by chance.

🤖 Generated with Claude Code

https://claude.ai/code/session_01SKtJsfjasPuTLtS3mEXFru

…fore LINQ

StandInPipelines.SkippedBeforeSummary and OnDemandPrograms.Summary ran OrderByDescending over a ConcurrentDictionary
other threads add to. Enumerable.ToArray sizes its array by the collection's Count and then calls CopyTo, which throws
ArgumentException when an entry was added in between. On the sampler thread (--sample-threads) that is unhandled: a
boot ended at 4,200 presents with 0xE0434352. ConcurrentDictionary.ToArray takes the entries under its locks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SKtJsfjasPuTLtS3mEXFru
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant