From e4f29edde49e93e1d4b42b83043c4d0a6de21f17 Mon Sep 17 00:00:00 2001 From: Robin Snyders Date: Wed, 25 Nov 2026 07:48:18 +0100 Subject: [PATCH] Loader: summaries take a snapshot of their concurrent dictionaries before 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 Claude-Session: https://claude.ai/code/session_01SKtJsfjasPuTLtS3mEXFru --- .../Shims/D3D12X/Pipelines/OnDemandPrograms.cs | 6 ++++-- .../Shims/D3D12X/Pipelines/StandInPipelines.cs | 7 +++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/FiveStar.Loader/Shims/D3D12X/Pipelines/OnDemandPrograms.cs b/src/FiveStar.Loader/Shims/D3D12X/Pipelines/OnDemandPrograms.cs index 66efe84d..8687d30d 100644 --- a/src/FiveStar.Loader/Shims/D3D12X/Pipelines/OnDemandPrograms.cs +++ b/src/FiveStar.Loader/Shims/D3D12X/Pipelines/OnDemandPrograms.cs @@ -66,8 +66,10 @@ public string Summary var ready = Math.Max(1, Volatile.Read(ref _ready)); var average = TimeSpan.FromTicks(Interlocked.Read(ref _readyTicks) / ready).TotalSeconds; var slowest = TimeSpan.FromTicks(Interlocked.Read(ref _slowestTicks)).TotalSeconds; - var failed = _failures.Values.Sum(); - var causes = string.Join("; ", _failures.OrderByDescending(entry => entry.Value).Take(CausesShown).Select(entry => $"{entry.Value} {entry.Key}")); + // A snapshot: LINQ over the dictionary itself sizes an array by Count, then copies while workers add causes. + var failures = _failures.ToArray(); + var failed = failures.Sum(entry => entry.Value); + var causes = string.Join("; ", failures.OrderByDescending(entry => entry.Value).Take(CausesShown).Select(entry => $"{entry.Value} {entry.Key}")); return $"programs on demand: {_jobs.Count} asked for, {Volatile.Read(ref _made)} translated and compiled, {Volatile.Read(ref _found)} found compiled{_compilerCounts?.Invoke()}, ready after {average:F1} s on average and {slowest:F0} s at most, {failed} failed ({causes}), {_workers.Backlog} queued, {_workers.Running} running, {_workers.WaitingForMemory} waiting for memory, {Links.Summary}"; } diff --git a/src/FiveStar.Loader/Shims/D3D12X/Pipelines/StandInPipelines.cs b/src/FiveStar.Loader/Shims/D3D12X/Pipelines/StandInPipelines.cs index 176d9fc8..f8685adc 100644 --- a/src/FiveStar.Loader/Shims/D3D12X/Pipelines/StandInPipelines.cs +++ b/src/FiveStar.Loader/Shims/D3D12X/Pipelines/StandInPipelines.cs @@ -432,8 +432,11 @@ private void CountSkippedBefore(nint standIn) private string SkippedBeforeSummary() { - var total = _skippedBefore.Values.Sum(); - var top = string.Join(", ", _skippedBefore.OrderByDescending(entry => entry.Value).Take(SkipsShown).Select(entry => $"{entry.Key} x{entry.Value}")); + // A snapshot: LINQ over the dictionary itself sizes an array by Count, then copies while lists add entries + // (ArgumentException on the sampler thread, which ended a boot at 4,200 presents). + var entries = _skippedBefore.ToArray(); + var total = entries.Sum(entry => entry.Value); + var top = string.Join(", ", entries.OrderByDescending(entry => entry.Value).Take(SkipsShown).Select(entry => $"{entry.Key} x{entry.Value}")); return $"{total} lists ran work after a skipped one ({top})"; }