Skip to content

Skia: rendering starves Idle/Low dispatcher work, hanging RunIdleAsync (macOS runtime tests time out)Β #24032

Description

@MartinZikmund

Current behavior πŸ›

On Skia, NativeDispatcher can starve its Low and Idle priority queues indefinitely while rendering is
active. Anything awaiting CoreDispatcher.RunIdleAsync then never resumes β€” the app is not deadlocked (it keeps
rendering) but idle-priority work stops making progress for minutes at a time.

The starvation path β€” src/Uno.UI.Dispatching/Native/NativeDispatcher.cs:

DispatchItems consults TryGetRenderAction() before it scans the four priority queues (:134), so a pending
render action outranks every queued item. The only anti-starvation guard is
normalItemsToProcessBeforeNextRenderAction, and it counts the Normal queue alone:

// :216 β€” budget re-seeded from the Normal queue only
_compositionTargets[compositionTarget] = (renderAction: null,
    normalItemsToProcessBeforeNextRenderAction: _queues[(int)NativeDispatcherPriority.Normal].Count);

// :156 β€” and decremented only when a Normal item is dispatched
if (@this._currentPriority == NativeDispatcherPriority.Normal) { ... }

When the Normal queue is empty β€” the ordinary state on a settled visual tree β€” the budget is re-seeded to 0 on
every render, so the next render action is immediately eligible again and Low/Idle never get a turn.

What keeps render actions arriving β€” src/Uno.UI/UI/Xaml/Media/CompositionTarget.Rendering.skia.cs:168:

if (_isRenderingActive) { ((ICompositionTarget)this).RequestNewFrame(); }

_isRenderingActive is a process-wide static (:28) that is true whenever any CompositionTarget.Rendering
subscriber exists. In practice that means a live ScrollPresenter (:6632), ScrollView (:1125), any
Storyboard via DispatcherAnimator (:19), BuildTreeScheduler (:90), ItemsView (:584),
ViewportManagerWithPlatformFeatures (:431) or an in-flight GestureRecognizer inertia processor (:351).
So a scrolling list, or any running animation, is enough to arm the loop.

Why macOS is where it bites. macOS is the only Skia host without a render thread or frame pacer
(grep -rln FramePacer src matches Win32 and X11 only). MacOSWindowHost.InvalidateRender()
(src/Uno.UI.Runtime.Skia.MacOS/UI/Xaml/Window/MacOSWindowHost.cs:288) is a bare uno_window_invalidate β†’
needsDisplay = YES, and AppKit then draws on the dispatcher's own thread, so display and dispatch interleave
roughly 1:1 and the render action is essentially always pending. Win32 documents this precise hazard in-code at
src/Uno.UI.Runtime.Skia.Win32/Rendering/Win32WindowWrapper.Rendering.cs:19-24.

User-visible impact beyond CI. Everything that relies on idle-priority work can stall on macOS while a
ScrollViewer or a Storyboard is live β€” CoreDispatcher.RunIdleAsync callbacks, CommandBar close
(CommandBar.Partial.cs:359), template-pool scavenging (FrameworkTemplatePoolDefaultPlatformProvider.cs:69),
DispatcherConditionalDisposable cleanup.

How it shows up in CI. The Tests - Desktop Skia macOS stage runs every runtime test in one process and hits
its 60-minute cap. Individual tests freeze in total log silence β€” no rendering warnings, no exceptions β€” then
resume and pass:

15:47:48.4488370Z  Running test When_Focused_Element_In_Scaled_Viewbox()
                   [ 22 min 27 s, zero log output ]
16:10:15.5132900Z  Running test When_Focused_Element_Scrolled()

Across 124 macOS task logs there are 74 silent gaps longer than 120 s; in 47 of them the gap opens
immediately after the Running test marker, i.e. inside the first await WaitForIdle() after WindowContent
is assigned. Stall durations are unquantized (250 s … 2047 s), so nothing is timing out β€” the wait simply
resumes when the interleave happens to break.

Measured on master, per-test durations parsed from the CI task logs:

window runs median suite median time stalled runs affected
2026-04-23 β†’ 06-05 16 24.5 min 6.5 min 10 / 16
2026-06-06 β†’ 07-15 29 20.5 min 0.2 min 0 / 29
2026-07-16 β†’ 08-10 54 36.1 min 10.9 min 52 / 54

Windows runs the same commits in 15.2 min and never stalls. Tests observed stalling, all of which hold a live
CompositionTarget.Rendering subscription at the moment they wait:

  • Given_SystemFocusVisual.When_Focused_Element_In_Scaled_Viewbox (worst: 1613 s)
  • Given_SystemFocusVisual.When_Focused_Element_Scrolled (worst: 2047 s)
  • Given_SystemFocusVisual.When_Focused_Element_Transformed, …_With_Multiple_Parent_Transforms
  • Given_TextBlock.When_Focus_Changes_Selection_Is_Not_Shown (worst: 769 s)
  • Given_ListViewBase.When_Reorder_DragDrop_ReusesContainers (worst: 1419 s), …When_UpdateLayout_In_DragDropping
  • CommandBarIntegrationTests.ValidateOverflowButtonHidesWhenAppropriate*

A May 2026 instance of the same failure shape (Given_TextBox.When_Touch_Focused_Then_Scrolled_Away, 250–1650 s
on 10 of 16 runs) stopped on 2026-06-05 at 458be6f70d, which removed a per-frame
FrameRendered β†’ Enqueue(…, Idle) keep-alive in TextBox.skia.cs β€” the same mechanism, cured by removing the
thing that kept the loop armed rather than by fixing the starvation.

This is not attributable to a single commit. A build on feature/breakingchanges @ 004885fda6 from
2026-07-14 stalled 35 min 24 s while containing none of the commits that bracket the July step change.

Expected behavior 🎯

Idle- and Low-priority dispatcher work makes forward progress regardless of how many render actions are pending.
await CoreDispatcher.Main.RunIdleAsync(...) should complete within a frame or two even while a
CompositionTarget.Rendering subscriber is keeping the render loop armed, and rendering should keep advancing
while idle work is queued β€” neither side may starve the other.

How to reproduce it (as minimally and precisely as possible) πŸ”¬

No sample app is needed β€” this reproduces inside the framework's own runtime tests. Minimal case on Skia macOS:

  1. Subscribe a no-op handler to CompositionTarget.Rendering (this is what a live ScrollViewer or any
    Storyboard does), which sets the process-wide _isRenderingActive and re-arms a render request every frame.
  2. await CoreDispatcher.Main.RunIdleAsync(_ => { }) on the UI thread.
  3. The idle callback is not invoked for an unbounded time β€” observed from seconds to over 30 minutes.

A regression test covering exactly this is added in the linked PR
(src/Uno.UI.RuntimeTests/Tests/Uno_UI_Dispatching/Given_NativeDispatcher.cs): it asserts the idle callback runs
within a generous ceiling, and asserts the converse β€” that frames continue to advance while idle work is queued.

End-to-end, the stall is intermittent (~40 % of CI runs for the worst test), so reproduce by running
Given_SystemFocusVisual repeatedly on Skia macOS rather than expecting a single run to hang.

Workaround πŸ› οΈ

For applications: none. Avoiding idle-priority work is not practical, since the framework itself schedules on it.

For CI, mitigations that make the stage survive without addressing the defect: a default per-test timeout in
UnitTestsControl (GetTestTimeout currently returns null unless a test carries [Timeout], so the runner
falls through to a bare await task), bounding TestServices.WindowHelper.WaitForIdle() (two RunIdleAsync
awaits with no timeout β€” and WaitFor only checks its deadline between awaits, so its nominal 1000 ms timeout
can never fire), and sharding the macOS stage the way the WebAssembly/Android/iOS stages already do.

Renderer 🎨

Skia

Affected platforms πŸ“±πŸ’»πŸ–₯️

Desktop (macOS) β€” reproduced and measured here. The starvation logic itself is in shared code compiled for
Skia, WebAssembly, native Android and native iOS; the other hosts have not been observed to stall, and Win32/X11
avoid it because they produce frames on a separate paced thread.

Uno.Sdk version (and other relevant versions) πŸ“¦

Uno Platform repository master @ 792ab0c6f4 (6.8-dev). Reproduced on CI images macos-15 and locally on
macOS 15 / .NET SDK 10.0.103.

Anything else we need to know? πŸ’¬

The obvious patch β€” widening normalItemsToProcessBeforeNextRenderAction to count all four queues while leaving
the decrement in the _currentPriority == Normal branch β€” deadlocks rendering: once the Normal queue drains,
the budget never returns to 0 and no render action is ever handed out again. Any fix must keep both directions
bounded.

src/Uno.UI/UI/Xaml/Media/CompositionTarget.Rendering.skia.cs:79 also declares
internal event Action? FrameRendered;, which AGENTS.md prohibits outright (EventHandler/EventHandler<T>
only). Unrelated to this bug, but in the same file.

Activity

  1. added
    triage/untriaged
    on Aug 10, 2026
  2. MartinZikmund commented on Oct 14, 2026

    @MartinZikmund
    MemberAuthor

    Details from duplicate #24005 that are not in this issue yet:

    • CI impact: median Tests - Desktop Skia macOS job time went from ~26 to ~37-42 min on all branches at once on 2026-07-16. That produced 87 timeout occurrences across job attempts (bc-branch 17/58, bc-pr 46/203, master 24/142). Master's are largely masked by a 41.3% stage retry rate.
    • Tests where the 28 final-attempt timeouts froze: Given_SystemFocusVisual (12), ListViewBase.When_Reorder_DragDrop_ReusesContainers (5), ScrollViewer.When_TouchScrollDownWithInertia_Then_DoNotChainInertia (5), TextBlock.When_Focus_Changes_Selection_Is_Not_Shown (4).
    • Ruled out: slow agents (other steps flat), hosted image rotation (macOS-14 never changed version but degraded the same day), suite growth (+2.19% tests vs +73% wall clock), generic SamplesApp regression (Linux 1.075x, Windows 1.03x).
    • Caveat: the stalls explain only ~60-70% of the regression. After subtracting every gap of 100 s or more, the median in-process span still rises 21.02 -> 27.17 min (+29%). A separate, unexplained ~25% macOS-only baseline regression landed the same day and needs its own investigation.
    • Do not scope a fix to one test: the longest stall landed on 5 distinct tests in 4 classes.
    • Raising timeoutInMinutes is not advisable: 4 of 9 sampled stalls ran 26-40 min.
    • Evidence: anonymous ADO REST, e.g. https://dev.azure.com/uno-platform/1dd81cbd-cb35-41de-a570-b0df3571a196/_apis/build/builds/223736/logs/1177?api-version=7.1 (25m36s gap). Stall watchdog/heartbeat work is in #24004.
  3. added
    7.0
    on Oct 14, 2026
  4. removed
    triage/untriaged
    7.0
    on Oct 29, 2026
  5. self-assigned this
    on Oct 30, 2026
  6. added 4 commits that reference this issue on Nov 3, 2026
    f6f4145
    76ec74a
    159b639
    c82ae1c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions