Open Bug 2085065 Opened 1 month ago Updated 26 days ago

GetUiaClientPidsWin11 enumerates every handle on the system synchronously on the parent main thread; main thread pegged 40-55 s at startup when a UIA client (DeepL) is running and a process holds ~10M handles

Categories

(Core :: Disability Access APIs, defect)

Firefox 158
x86_64
Windows 11
defect

Tracking

()

UNCONFIRMED

People

(Reporter: 03solpy, Unassigned)

References

(Blocks 1 open bug)

Details

Environment

  • Firefox 158.0.1 (64-bit), buildID 20261019185856, release channel
  • Windows 11 Pro (build 26200), x64, 12 logical CPUs, 64 GB RAM
  • Reproduces with a brand-new profile and no extensions
  • UIA client that triggered it in practice: DeepL desktop app 26.9.1.21220 (reported as a11y.instantiators = DeepL.exe|26.9.1.21220 in telemetry). It reads selected text from other apps through UI Automation.

What happened

Whenever Firefox started, the parent process pegged one CPU core at 100% for 40-55 seconds before the GPU/content processes and the first tab appeared. Its working set jumped by ~390 MB at the same moment. Chrome and Edge started normally on the same machine.

The machine had ~10.3 million handles in total, ~10 million of them leaked by one unrelated process (a long-running MSYS2/Git-for-Windows find / that never exited). 10M handles x 40 bytes per SYSTEM_HANDLE_TABLE_ENTRY_INFO_EX is ~400 MB, which matches the working-set jump.

  • After killing that process (system total back to ~200k handles), Firefox started normally (tabs up in ~2 s, settled in ~4-5 s, 3/3 launches).
  • Uninstalling DeepL also made the problem go away.

Stack (parent main thread)

I suspended the main thread about 300 times at 30 ms intervals, walked the stack, and symbolicated it with the Mozilla symbol server. 296/300 samples had this leaf:

ntdll!ZwQuerySystemInformation
xul!GetUiaClientPidsWin11::Run(nsTArray<unsigned long>&)                    accessible/windows/msaa/CompatibilityUIA.cpp:199
xul!mozilla::a11y::Compatibility::GetUiaClientPids(nsTArray<unsigned long>&) CompatibilityUIA.cpp:409
xul!mozilla::a11y::LazyInstantiator::ShouldInstantiate()                     LazyInstantiator.cpp:282
xul!mozilla::a11y::LazyInstantiator::MaybeResolveRoot()                      LazyInstantiator.cpp:352
xul!mozilla::a11y::LazyInstantiator::QueryInterface(_GUID const&, void**)    LazyInstantiator.cpp:448
UIAutomationCore / OneCoreCommonProxyStub / rpcrt4 (incoming COM call)
user32!CallWindowProcW
xul!NS_ProcessNextEvent
...
xul!XRE_main
firefox!wmain

The remaining 4/300 samples were in NtFreeVirtualMemory via mozglue. That suggests the enumeration buffer is being freed and reallocated, i.e. the query is retried more than once (not confirmed).

Synthetic reproduction (no DeepL needed)

Steps:

  1. Start a helper process that creates N unnamed event handles (CreateEventW in a loop) and keeps them open. Optionally, have it also create and close 2000 more handles in a tight loop ("churn").
  2. Start Firefox with a fresh profile (-no-remote -profile <empty dir>) and wait for startup to settle.
  3. From another process, run a UIA query against the Firefox top-level window. For example, in PowerShell with UIAutomationClient: [System.Windows.Automation.AutomationElement]::FromHandle($hwnd).FindAll('Children', TrueCondition).
  4. Measure how long the call takes and how much CPU the Firefox parent process uses during it.
Total handles on system UIA call duration Firefox parent CPU during call
~0.2M (normal) 0.0 s 0.0 s
~2.2M 0.4 s 0.3 s
~5.2M 0.8 s 0.7 s
~9.7M (static) 0.7 s 0.7 s
~9.7M + churn 1.5 s 1.4-1.5 s
~9.7M + churn, accessibility.force_disabled=1 0.9 s 0.8 s

So the cost grows with the number of handles on the whole system, it is paid on the parent main thread, and accessibility.force_disabled=1 does not skip it. My synthetic setup did not reproduce the full 40-55 s seen with the real leaking process. Something about that process, perhaps the handle types or how it kept growing, made the query far slower or made it retry many times. I couldn't isolate which.

Expected

A UIA client connecting should not make the browser's main thread do work that scales with every handle in the OS, at least not unbounded and synchronously. Possible mitigations:

  • bound the enumeration (time or retry cap), or do it off the main thread;
  • add slack when growing the buffer after STATUS_INFO_LENGTH_MISMATCH, so a changing handle count doesn't cause repeated retries;
  • cache the result per client connection;
  • skip the check entirely when accessibility is force-disabled.

Related

  • Bug 1854040 / bug 1899211: GetUiaClientPidsWin11 hanging forever. Those are deadlocks on a specific named pipe (e.g. Dropbox), fixed. This report is a different failure mode: CPU-bound, and proportional to the system-wide handle count.
  • Bug 1876192: hangs in UIAutomationCore on Windows 11.
Severity: -- → S3
You need to log in before you can comment on or make changes to this bug.