Skip to content

Try to log exceptions in IoThread#14899

Merged
seanbudd merged 2 commits into
nvaccess:masterfrom
LeonarddeR:tryCatchIoThread
May 4, 2023
Merged

Try to log exceptions in IoThread#14899
seanbudd merged 2 commits into
nvaccess:masterfrom
LeonarddeR:tryCatchIoThread

Conversation

@LeonarddeR

Copy link
Copy Markdown
Collaborator

Link to issue number:

None

Summary of the issue:

I'm still seeing access violations in the IoThread here and there, same for @bramd. I really want to track these down! We need to handle those more gracefully anyway.

Description of user facing changes

Better logging

Description of development approach

De run block of the IOThread is now wrapped in a try/except that logs the stack. I hope the stack will give us more info about what's going wrong here.

Testing strategy:

No longer stuff like this in the logThere should no longer be stuff like this in the log:

ERROR - stderr (14:44:14.406) - hwIo.ioThread.IoThread (24944):
Exception in thread hwIo.ioThread.IoThread:
Traceback (most recent call last):
  File "threading.pyc", line 926, in _bootstrap_inner
  File "hwIo\ioThread.pyc", line 201, in run
OSError: exception: access violation reading 0x05B50058

Rather, it should be a critical error that logs the stack. This pr needs a follow up to handle the underlying issue.

Known issues with pull request:

I can only test this with a signed try build, though I'm pretty sure this can go to Alpha pretty safely.

Change log entries:

None needed as this isn't a fix, it only improves logging to track down the underlying issue.

Code Review Checklist:

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

@LeonarddeR LeonarddeR requested a review from a team as a code owner May 3, 2023 12:50
@LeonarddeR LeonarddeR requested a review from seanbudd May 3, 2023 12:50
Comment thread source/hwIo/ioThread.py Outdated
Comment thread source/hwIo/ioThread.py Outdated
if self.exit:
break
except Exception:
log.critical("Exception in IoThread function", exc_info=True, stack_info=True)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Using exc_info=True and stack_info=True) seems unusual. What is expected?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Well, it should log the exception as well as a strack trace.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Actually, good catch. I want to log not only a stack trace from the IoThread, but dump the stack of all threads, like the watchdog does.

@LeonarddeR LeonarddeR marked this pull request as draft May 4, 2023 06:58
@LeonarddeR LeonarddeR marked this pull request as ready for review May 4, 2023 07:06
Comment thread source/hwIo/ioThread.py
from inspect import ismethod
from buildVersion import version_year
import NVDAState
from watchdog import getFormattedStacksForAllThreads

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since it is not used only for watchdog, would it be worth to move getFormattedStacksForAllThreads in a log-related file? E.g. logHandler.py

With watchdog.getFormattedStacksForAllThreads remaining but being deprecated.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I think that makes sense, but then we could also extend the stack_info argument to take something to log all stacks. That might be something more suitable for a follow up.

@seanbudd seanbudd merged commit d1ce3bc into nvaccess:master May 4, 2023
@nvaccessAuto nvaccessAuto added this to the 2023.2 milestone May 4, 2023
seanbudd pushed a commit that referenced this pull request Jun 2, 2023
Related to #14899, #14312, #14627
Fixes #14895

Summary of the issue:
Despite several attempts to fix this, NVDA's IoThread can crash without a clear cause.

Description of user facing changes
Less crashes, most likely, as tests indicate that this is the case.

Description of development approach
As proposed by @jcsteh , rather than creating a new function pointer for every APC or completion routine call, use a single internal APC and completion routine and use an internal cache to store the python functions, not the actual APC functions.
seanbudd pushed a commit that referenced this pull request Oct 12, 2023
…fix build of developer documentation. (#15616)

Related to #12971 problem caused by PR #14899

Summary of the issue:
When trying to build developer documentation with Sphinx, many modules failed to be parsed

Description of development approach
getFormattedStacksForAllThreads is moved from watchdog to the logHandler, which avoids these warnings. Appropriate backwards compatibility is added to watchdog, to make sure add-on authors are warned to use the moved function from logHandler in the future.
@LeonarddeR LeonarddeR deleted the tryCatchIoThread branch August 23, 2025 06:28
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