Skip to content

Rate limiting against gui crash#19686

Merged
SaschaCowley merged 6 commits intobetafrom
try-gui-crash
Mar 11, 2026
Merged

Rate limiting against gui crash#19686
SaschaCowley merged 6 commits intobetafrom
try-gui-crash

Conversation

@seanbudd
Copy link
Copy Markdown
Member

@seanbudd seanbudd commented Feb 25, 2026

Link to issue number:

Blocked by #19702
Fixes #19634

Summary of the issue:

Windows throws errors when rapidly requesting a window handle on the secure desktop.
This cause visual tearing and a crash of NVDA.

Description of user facing changes:

Avoid crash and tearing of controls

Description of developer facing changes:

Add custom handling of changing settings categories for secure mode.

Description of development approach:

This pull request introduces a debounced category change mechanism in the NVDASettingsDialog to improve stability and user experience, particularly when running on a secure desktop.

  • Added a debounce mechanism (50ms delay) for handling category changes in NVDASettingsDialog when running on a secure desktop, using a timer to prevent rapid or duplicate category switches. This helps avoid potential issues with UI responsiveness or event handling in secure desktop environments. [1] [2]
  • Introduced the use of isRunningOnSecureDesktop from utils.security to determine when to apply the debounce logic.
  • Added type annotations to the onCategoryChange method and new internal variables for better code clarity and maintainability. [1] [2]
  • Ensured proper cleanup of the debounce timer and related state in the Destroy method to prevent resource leaks.

An alternative approach with error suppression was tried, but visual tearing still occurred.
https://github.com/nvaccess/nvda/compare/try-gui-crash-2?expand=1

Testing strategy:

Tested STR in #19634

Known issues with pull request:

Other instances may exist of rapidly requesting a window handle.
Should this be reported to wxWidgets or microsoft?
Should we create a generic monkey patch or something?
From basic investigating, the only real way to cause this could be through updating controls in the settings dialog, or the config profiles dialog.

Code Review Checklist:

  • Documentation:
    • Change log entry
    • User Documentation
    • Developer / Technical Documentation
    • Context sensitive help for GUI changes
  • Testing:
    • Unit tests
    • System (end to end) tests
    • Manual testing
  • UX of all users considered:
    • Speech
    • Braille
    • Low Vision
    • Different web browsers
    • Localization in other languages / culture than English
  • API is compatible with existing add-ons.
  • Security precautions taken.

@seanbudd seanbudd marked this pull request as ready for review February 25, 2026 05:15
@seanbudd seanbudd requested a review from a team as a code owner February 25, 2026 05:15
@seanbudd seanbudd added this to the 2026.1 milestone Feb 25, 2026
@seanbudd
Copy link
Copy Markdown
Member Author

Hi @CyrilleB79 - could you test with this try build?

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses a secure-desktop-only NVDA settings dialog instability/crash triggered by rapid category switching (issue #19634). It adds a small debounce layer around category changes when NVDA is running on the secure desktop to reduce rapid UI rebuilds that can lead to control tearing and crashes.

Changes:

  • Added a 50ms debounce for settings category changes on the secure desktop via wx.CallLater.
  • Introduced secure-desktop detection (isRunningOnSecureDesktop) to conditionally apply the debounce logic.
  • Ensured debounce timer/state is cleaned up when the settings dialog is destroyed.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions github-actions Bot requested a deployment to snapshot February 25, 2026 06:03 Abandoned
Comment thread source/gui/settingsDialogs.py Outdated
Comment thread source/gui/settingsDialogs.py
Comment thread source/gui/settingsDialogs.py
@seanbudd seanbudd added the conceptApproved Similar 'triaged' for issues, PR accepted in theory, implementation needs review. label Feb 26, 2026
@seanbudd seanbudd mentioned this pull request Feb 26, 2026
5 tasks
@CyrilleB79
Copy link
Copy Markdown
Contributor

I won't probably not be able to test before the end of this week. Though, since the PR is in Draft state, do I still need to test it now or should I wait for #19702?

@seanbudd
Copy link
Copy Markdown
Member Author

Either way is appreciated. Testing now confirms that debouncing fixes the problem, testing later confirms our next debouncing algorithm works still

@CyrilleB79
Copy link
Copy Markdown
Contributor

Hi.

I have just tested nvda_snapshot_try-gui-crash-54816,4ece670b.exe, with service debug key enabled so that I can take a log from the secure screen.

Unfortunately, the issue is still reproducible switching between categories or maintaining the tab key pressed to move the focus around controls. Here is the log: nvda.log

I have used ctrl+alt+suppr screen from my session to experiment.

@seanbudd
Copy link
Copy Markdown
Member Author

seanbudd commented Mar 4, 2026

Is this something you can reproduce without the serviceDebug key? I think there might be a separate issue with certain controls showing while in serviceDebug mode when they shouldn't

@CyrilleB79
Copy link
Copy Markdown
Contributor

Is this something you can reproduce without the serviceDebug key?

I'd say yes, but let me double check Tonight (Europe time) to be sure. I'll let you know.

@CyrilleB79
Copy link
Copy Markdown
Contributor

Is this something you can reproduce without the serviceDebug key?

Just tested now. Unfortunately the issue is still present without the service debug key. Meybe a bit more difficult to reproduce; it's a bit hard to say since the issue occurs only rarely except when I perform stress tests.

seanbudd added a commit that referenced this pull request Mar 5, 2026
Inspired by #19686
Summary of the issue:

We regularly run into problems where the GUI being updated frequently causing issues.
We fix this using a ratelimiter/debouncer.
We do not have a generic debouncer in NVDA.
Description of user facing changes:

none
Description of developer facing changes:

Adds a generic debouncer to NVDA
Description of development approach:

This pull request introduces a new debouncing utility for limiting the frequency of function calls, primarily to improve GUI responsiveness and reduce unnecessary processing in NVDA. The main changes include the addition of the debounceLimiter decorator, its integration into the browseMode.py file for filtering elements, and comprehensive unit tests to verify its behavior. The pull request also modernizes type annotations throughout browseMode.py for improved readability and consistency.

Debounce utility and integration:

    Added a new debounceLimiter decorator in utils/debounce.py to control the execution rate of functions, supporting both GUI and daemon threads.
    Integrated debounceLimiter into the filtering logic of the elements list dialog in browseMode.py, replacing manual timer handling for improved efficiency and code clarity
@seanbudd
Copy link
Copy Markdown
Member Author

seanbudd commented Mar 6, 2026

I've found I could also reproduce still, but less frequently. I've upped the debounce time significantly for testing again

@github-actions github-actions Bot requested a deployment to snapshot March 6, 2026 08:49 Abandoned
@seanbudd
Copy link
Copy Markdown
Member Author

seanbudd commented Mar 10, 2026

I can't reproduce with the very high debouce limit.
Can you confirm with testing @CyrilleB79 - try build?
I think we should merge with the higher limit, and reduce it on alphas if need be.

@seanbudd seanbudd marked this pull request as ready for review March 10, 2026 02:57
@seanbudd seanbudd requested a review from SaschaCowley March 10, 2026 02:57
@CyrilleB79
Copy link
Copy Markdown
Contributor

OK, I'll test tonight (CET)

@CyrilleB79
Copy link
Copy Markdown
Contributor

I have just tested nvda_snapshot_try-gui-crash-54962,3ca5270b.exe.

Unfortunately, the issue is still present. I can still reproduce GUI controls/panels mixing (3 times) after about 30 seconds of stress tests with tab, shift+tab, ctrl+tab and ctrl+shift+tab to navigate between controls and panels.

@seanbudd
Copy link
Copy Markdown
Member Author

Thanks for testing @CyrilleB79. I think we are going to keep the current limits for now, since they seem to work for the average user. I think the tradeoff between usability and preventing the crash is best at around 500ms. I hope beyond stress testing, that should be enough to prevent a crash for the average user?

@SaschaCowley SaschaCowley merged commit d3596a7 into beta Mar 11, 2026
76 of 78 checks passed
@SaschaCowley SaschaCowley deleted the try-gui-crash branch March 11, 2026 01:42
SaschaCowley added a commit that referenced this pull request Mar 25, 2026
SaschaCowley added a commit that referenced this pull request Mar 25, 2026
SaschaCowley added a commit that referenced this pull request Mar 25, 2026
Reverts #19686

### Issues fixed
None

### Issues reopened
#19634

### Reason for revert
Flawed approach

### Can this PR be reimplemented? If so, what is required for the next
attempt
We are going to limit which panels are available on secure desktops as a
temporary mitigation attempt.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

conceptApproved Similar 'triaged' for issues, PR accepted in theory, implementation needs review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants