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

Guard against recorder pool current connection disappearing during global destruction #71971

Merged
merged 1 commit into from
May 16, 2022

Conversation

bdraco
Copy link
Member

@bdraco bdraco commented May 16, 2022

Proposed change

self._conn.current is a weak reference. It can already be destroyed at shutdown

cc @chemelli74

Fixes

2022-05-16 11:32:10 ERROR (DbWorker_3) [root] Uncaught thread exception
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/threading.py", line 973, in _bootstrap_inner
    self.run()
  File "/usr/local/lib/python3.9/threading.py", line 910, in run
    self._target(*self._args, **self._kwargs)
  File "/workspaces/core/homeassistant/components/recorder/executor.py", line 18, in _worker_with_shutdown_hook
    shutdown_hook()
  File "/workspaces/core/homeassistant/components/recorder/core.py", line 245, in _shutdown_pool
    self.engine.pool.shutdown()
  File "/workspaces/core/homeassistant/components/recorder/pool.py", line 58, in shutdown
    if self.recorder_or_dbworker and self._conn and (conn := self._conn.current()):
AttributeError: _thread._local object has no attribute current

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • The code has been formatted using Black (black --fast homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 🥈 Silver
  • 🥇 Gold
  • 🏆 Platinum

To help with the load of incoming pull requests:

`self._conn.current` is a weak reference. It can already be destroyed at shutdown

Fixes
```
2022-05-16 11:32:10 ERROR (DbWorker_3) [root] Uncaught thread exception
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/threading.py", line 973, in _bootstrap_inner
    self.run()
  File "/usr/local/lib/python3.9/threading.py", line 910, in run
    self._target(*self._args, **self._kwargs)
  File "/workspaces/core/homeassistant/components/recorder/executor.py", line 18, in _worker_with_shutdown_hook
    shutdown_hook()
  File "/workspaces/core/homeassistant/components/recorder/core.py", line 245, in _shutdown_pool
    self.engine.pool.shutdown()
  File "/workspaces/core/homeassistant/components/recorder/pool.py", line 58, in shutdown
    if self.recorder_or_dbworker and self._conn and (conn := self._conn.current()):
AttributeError: _thread._local object has no attribute current
```
@probot-home-assistant
Copy link

Hey there @home-assistant/core, mind taking a look at this pull request as it has been labeled with an integration (recorder) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)

Copy link
Contributor

@chemelli74 chemelli74 left a comment

Choose a reason for hiding this comment

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

LGTM!

@bdraco bdraco changed the title Guard against current connection disappearing during global destruction Guard against recorder pool current connection disappearing during global destruction May 16, 2022
@bdraco bdraco merged commit f4a2afe into home-assistant:dev May 16, 2022
@bdraco bdraco deleted the guard_db_pool_shutdown branch May 16, 2022 22:48
@github-actions github-actions bot locked and limited conversation to collaborators May 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants