Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UIA freezes after a large number of events is received #11002

Closed
codeofdusk opened this issue Apr 14, 2020 · 12 comments
Closed

UIA freezes after a large number of events is received #11002

codeofdusk opened this issue Apr 14, 2020 · 12 comments
Labels
api/uia Feature or bug requires an understanding of UIA bug/app-freeze p2 https://github.com/nvaccess/nvda/blob/master/projectDocs/issues/triage.md#priority performance triaged Has been triaged, issue is waiting for implementation.

Comments

@codeofdusk
Copy link
Contributor

Steps to reproduce:

  1. Enable "use UI Automation to access the Windows Console" from advanced preferences.

  2. Run cmd.

  3. Start a python interpreter: python.

  4. Run:

    for i in range(100000):
    print("test")

Actual behavior:

"test" is read for a few seconds, then all UIA applications become completely inaccessible until NVDA is restarted.

Expected behavior:

Output stops for a few seconds, then UIA recovers.

Context

I also tried disabling UIA connection recovery and event coalescing with the following in the NVDA Python console:

import UIAHandler
UIAHandler.handler.clientObject.CoalesceEvents = 0
UIAHandler.handler.clientObject.ConnectionRecoveryBehavior = 0

After UIA dies, running uiaHandler.terminate() and UIAHandler.initialize() does not restart UIA functionality. I'm not sure how to detect when UIA breaks or how to restart it once it does.

System configuration

NVDA installed/portable/running from source:

Installed and source.

NVDA version:

Latest master (b38776a).

Windows version:

Windows 10 21H1 insider.

Name and version of other software in use when reproducing the issue:

Windows Console

Other information about your system:

Other questions

Does the issue still occur after restarting your computer?

Yes.

Have you tried any other versions of NVDA? If so, please report their behaviors.

2019.2.1, 2019.3, 2020.1 (all same result).

If addons are disabled, is your problem still occuring?

Yes.

Did you try to run the COM registry fixing tool in NVDA menu / tools?

Not applicable.

@codeofdusk
Copy link
Contributor Author

Narrator seems to work as expected here, at least with my test case.

Cc @josephsl @LeonarddeR @michaelDCurran.

@LeonarddeR
Copy link
Collaborator

Hmm, this might be related to other UIA performance issues. cc @bramd

@francipvb
Copy link
Contributor

francipvb commented Apr 14, 2020 via email

@LeonarddeR
Copy link
Collaborator

I have the strong feeling that something @jcsteh wrote in #10508 (comment) is related to this:

Obviously, not listening to property change events altogether isn't an option. However, Narrator and JAWS don't seem to be impacted like NVDA is. Some thoughts on that:

1. This is another reason to again consider selectively registering for property change events (e.g. on focus + ancestors and progress bar value changes), rather than unconditionally listening to all of them.

2. If I Register for property change events but return at the top of IUIAutomationPropertyChangedEventHandler_HandlePropertyChangedEvent (so we receive the event but discard it), it's pretty responsive. That suggests we might be able to optimise some of the stuff we do in the event handler; e.g. constructing the object, choosing overlay classes, etc.

I would say that a solution based on option 2 would have the least chance of regressions while having positive impact on performance.

Now, I"m not sure what thread or threads handle all these events, as the log calls them dummy threads. However, if the UIA handler is processing an event and might be unable to process the next, if processing one event takes too much time without us discarding events that are out of date, things are slowing down. I think this is exactly what we're experiencing in several situations now, particularly in Visual Studio and may be in Word as well.

Cc @michaelDCurran @josephsl @bramd

@beqabeqa473
Copy link
Contributor

beqabeqa473 commented Apr 21, 2020 via email

@LeonarddeR
Copy link
Collaborator

Related to #11077

@codeofdusk
Copy link
Contributor Author

codeofdusk commented Jan 22, 2022

At least for consoles, a lot of this appears to be a result of us registering for the textChange and caret events in particular: rejecting them in EventHandler.shouldAcceptEvent does not stop NVDA's UIA support from hanging, but commenting out their entries in UIAHandler.UIAEventIdsToNVDAEventNames allows consoles with lots of text not to flood the system at the cost of autoread support.

Since consoles won't need these events any more once UIA notifications support is implemented for functional autoread, we should consider a way for NVDA not to register for these events from certain spammy providers, or only register for them in known-good cases. Thoughts @LeonarddeR, @michaelDCurran, @carlos-zamora?

seanbudd pushed a commit that referenced this issue Feb 16, 2022
…tification events for now and preserve accessibility after UIA class name change (#13261)

Link to issue number:
Related to microsoft/terminal#12358 among others (to be released).

Summary of the issue:
In upcoming Windows Terminal and Windows Console, UIA notification events will be sent when new text is inserted (i.e. for text output) to improve Narrator support. This will result in double-reporting of all terminal output: once from LiveText and once from UIA notifications (but without appropriate filtering for typed characters/passwords etc).

As part of the implementation of notifications, I asked Microsoft to change the UIA class name to allow new terminal support (including notifications) in a follow-up NVDA PR, since notifications will require a departure from the terminal strategy used by NVDA in the past. Changing the class name will break NVDA's current ability to identify the terminal and implement accessibility.

Description of how this pull request fixes the issue:
Suppress any received UIA notification events in UIA console and terminal for now, but log them for development.
Support the new UIA class name used by terminals that send notifications.
Ideally, NVDA would use these events in place of LiveText. If we could get away without registering for TextChange at all, this could be an extreme stability improvement in the terminal as #11002 would be completely circumvented. Also, having new text pushed to us (instead of having to diff) should improve performance considerably in high-volume scenarios.
@seanbudd seanbudd added p2 https://github.com/nvaccess/nvda/blob/master/projectDocs/issues/triage.md#priority triaged Has been triaged, issue is waiting for implementation. labels Jul 14, 2022
@seanbudd
Copy link
Member

Potentially related to #13334

@codeofdusk
Copy link
Contributor Author

Potentially related to #13334

Not quite, because Notepad on Windows 10 uses MSAA, not UIA. Notepad on Windows 11 is UIA based, and if this hang can be reproduced there it is caused by this issue. Similar issues in VS, Windows Terminal, and (UIA) console are also in scope.

seanbudd pushed a commit that referenced this issue Aug 16, 2022
Link to issue number:
Partial mitigation for #11002.
Follow-up of #11214 and #13297.

Summary of the issue:
NVDA 2020.3 introduced support for selective registration for UIA events based on the currently-focused provider, but this is disabled by default due to bugs in the Windows 10 task manager and emoji panel.
These bugs have been fixed in Windows 11 SV2.

Description of how this pull request fixes the issue:
By default, enable selective UIA event registration on Windows 11 Sun Valley 2 (22H2).

Testing strategy:
Enable by default in master snapshots to allow for wider testing.
@codeofdusk
Copy link
Contributor Author

Further investigation is required of course, but I think something along the lines of #10556 for UIA events would go a very long way here.

seanbudd pushed a commit that referenced this issue Aug 29, 2022
…Windows Terminal (#14067)

Mitigation for #11002.
Blocking #14047.

Summary of the issue:
UIA textChange NVDA events are seldom (if ever) used outside of a few specific situations, but have an extreme performance impact (see #11002).

Description of user facing changes
Improved performance/less chance of NVDA hanging in UIA applications.

Description of development approach
Explicitly do not process UIA textChange events outside of Windows Console, Terminal, and Word. The eventual end goal is to remove TermControl/TermControl2 from UIAHandler.textChangeUIAClassNames in #14047, which will very greatly improve performance in Windows Terminal. (conhost will remain, as there don't seem to be any plans to add notifications, especially as wt is becoming the default).

I'm very reluctant to add a mechanism by which add-ons/app modules can request textChange events unless someone requests it, especially given #11002.
@Adriani90
Copy link
Collaborator

This has been probably fixed by #14888. Closing as fixed, but feel free to comment in case the issue still exists in the last NVDA alpha version and we can reopen.

@LeonarddeR now that #14888 is merged, is selective registering for UIA events still needed at all? You implemented that in #11214.

@LeonarddeR
Copy link
Collaborator

@LeonarddeR now that #14888 is merged, is selective registering for UIA events still needed at all? You implemented that in #11214.

Yes, I think so. It generally doesn't make sense to register to events you don't need.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api/uia Feature or bug requires an understanding of UIA bug/app-freeze p2 https://github.com/nvaccess/nvda/blob/master/projectDocs/issues/triage.md#priority performance triaged Has been triaged, issue is waiting for implementation.
Projects
None yet
Development

No branches or pull requests

7 participants