Skip to content

Avoid crash in Chrome, issue 41487612#16893

Merged
seanbudd merged 6 commits intobetafrom
chromeIssue41487612
Jul 29, 2024
Merged

Avoid crash in Chrome, issue 41487612#16893
seanbudd merged 6 commits intobetafrom
chromeIssue41487612

Conversation

@michaelDCurran
Copy link
Member

@michaelDCurran michaelDCurran commented Jul 23, 2024

Link to issue number:

Fixes Chrome issue 41487612
Fixes Chrome crash introduced in NVDA pr #14647

Summary of the issue:

Google has detected crashes in Chrome when users are running NVDA.
Exact steps to reproduce are not known, but it is when an NVDA virtual buffer is destroyed. Could be on Chrome exit, NVDA exit, or closing a Chrome window.
Chrome issue: https://issues.chromium.org/issues/41487612
It shows that a COM object tries to be released from an RPC worker thread by NVDA's in-process code, which causes Chrome to crash.

NVDA pr #14647 introduced code to hold a reference to the document root accessible on the virtual buffer, so that NVDA could check if the document had died. However, it is this COM object that is automatically released when the virtual buffer id destroyed from an RPC worker thread.
The COM object should really however be released when the virtual buffer is terminated in the correct UI thread, before destruction.

Description of user facing changes

No longer cause Google Chrome to crash when closing a document or exiting Chrome.

Description of development approach

  • VBufBackend_gecko_ia2::renderThread_terminate: correctly release the document root accessible.
  • VBufBackend_gecko_ia2's destructor: in the very unlikely case where the VBufBackend_gecko_ia2::renderThread_terminate has not been called, detach the document root accessible, leaking it rather than inappropriately releasing it on the wrong thread.

Testing strategy:

  • With Firefox and Google Chrome with NvDA running, open and close many documents, and exit the browser many times, ensuring that no crash occurs.

Known issues with pull request:

In the very unlikely case that the virtual buffer cannot be terminated in the UI thread correctly (Perhaps that thread has been terminated, or the browser is exiting such that wm_destroy messages are not being sent), the document root accessible will be leaked I.e. never released. This may hold memory or other resources. However, the original behaviour of calling release from the wrong thread was much worse as it could crash the browser entirely.

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.

Summary by CodeRabbit

  • Bug Fixes
    • Improved memory management and resource cleanup to prevent potential memory leaks.
    • Enhanced stability of the backend by ensuring proper handling of critical resources during termination and destruction phases.

… when terminating the backend in the UI thread, and if this does not occur, leak the COM object rather than crashing the browser.
@michaelDCurran michaelDCurran requested a review from a team as a code owner July 23, 2024 01:10
@michaelDCurran michaelDCurran requested review from gerald-hartig and removed request for a team July 23, 2024 01:10
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 23, 2024

Walkthrough

The changes enhance the GeckoVBufBackend_t class by improving resource management in the renderThread_terminate method and the destructor. The modifications ensure that the rootDocAcc reference is properly released during termination and destruction, addressing potential memory management issues and preventing resource leaks. This results in increased stability and safety within the lifecycle of the backend.

Changes

Files Change Summary
nvdaHelper/vbufBackends/gecko_ia2/gecko_ia2.cpp Modified renderThread_terminate and destructor to ensure proper release of rootDocAcc, improving memory management and stability.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@michaelDCurran michaelDCurran requested a review from jcsteh July 23, 2024 01:11
@michaelDCurran michaelDCurran added this to the 2024.3 milestone Jul 23, 2024
@jcsteh
Copy link
Contributor

jcsteh commented Jul 23, 2024

In the very unlikely case that the virtual buffer cannot be terminated in the UI thread correctly (Perhaps that thread has been terminated, or the browser is exiting such that wm_destroy messages are not being sent), the document root accessible will be leaked I.e. never released.

I think terminating a thread or terminating its message loop without cleaning up COM objects would be a violation of COM rules on the part of the application anyway, so I wouldn't consider this a problem with this PR as such.

jcsteh
jcsteh previously approved these changes Jul 23, 2024
Copy link
Contributor

@jcsteh jcsteh left a comment

Choose a reason for hiding this comment

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

Sorry for the oversight.

// See https://issues.chromium.org/issues/41487612
// In most cases this will be released in renderThread_terminate.
// However in the unlikely case terminate can't run,
// it will be deleted along with the backend, but in an RPC thread!
Copy link
Contributor

Choose a reason for hiding this comment

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

This might be misconstrued to mean that even with the code below, it will be deleted from the wrong thread. Perhaps this could say "if we don't do anything here, it will be deleted along with..."

seanbudd
seanbudd previously approved these changes Jul 28, 2024
* Playing NVDA sounds no longer fails on a mono audio device. (#16770, @jcsteh)
* NVDA will report addresses when arrowing through To/CC/BCC fields in outlook.com / Modern Outlook. (#16856)
* NVDA now handles add-on installation failures more gracefully. (#16704)
* No longer cause Google Chrome to crash when closing a document or exiting Chrome. (#16893)
Copy link
Member

Choose a reason for hiding this comment

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

can you move this to the "web browser fixes" sub-list at the start of bug fixes

@seanbudd seanbudd merged commit c78f338 into beta Jul 29, 2024
@seanbudd seanbudd deleted the chromeIssue41487612 branch July 29, 2024 00:54
* NVDA will correctly announce radio and checkbox menu items when first entering sub-menus in Google Chrome and Mozilla Firefox. (#14550)
* NVDA's browse mode find functionality is now more accurate when the page contains emojis. (#16317, @LeonarddeR)
* In Mozilla Firefox, NVDA now correctly reports the current character, word and line when the cursor is at the insertion point at the end of a line. (#3156, @jcsteh)
* No longer cause Google Chrome to crash when closing a document or exiting Chrome. (#16893)
Copy link
Contributor

Choose a reason for hiding this comment

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

@michaelDCurran or @seanbudd, I am reviewing the translation of this item.

Translating this sentence sounds a bit strange because grammatically, the subject is missing in this sentence.

Said otherwise, I wonder, what (or who) no longer causes Chrome to crash? Is it NVDA?

Or maybe I haven't understood the sentence correctly...

@jcsteh
Copy link
Contributor

jcsteh commented Jul 31, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants