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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix race in notify setup #76954

Merged
merged 6 commits into from
Aug 18, 2022
Merged

Fix race in notify setup #76954

merged 6 commits into from
Aug 18, 2022

Conversation

bdraco
Copy link
Member

@bdraco bdraco commented Aug 17, 2022

Please see below. I may be missing something but it doesn't look like slack and discord pass hass_config which may be the actual root cause here (although I think there is still a race).

It would be helpful if someone could validate that or tell me I'm reading it wrong 馃槃

details: #76954 (comment)

Proposed change

The discovery dispatcher must be connected before we can add
to hass.config.components to ensure signals are
not missed since the legacy setup await can return control
to the event loop before it gets connected.

Fixes #76564
Fixes #76402
Fixes #76343
Fixes #76919

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)
  • Deprecation (breaking change to happen in the future)
  • 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:

The dispatcher must be connected before we can add
to `hass.config.components` to ensure signals are
missed
@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 (notify) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)

@bdraco bdraco added this to the 2022.8.6 milestone Aug 17, 2022
@bdraco
Copy link
Member Author

bdraco commented Aug 17, 2022

I think there is still a race here with yaml ones

I think we need to separate async_setup_legacy so we attach the, then add the comp, then setup platforms

    hass.data[NOTIFY_DISCOVERY_DISPATCHER] = discovery.async_listen_platform(
        hass, DOMAIN, async_platform_discovered
    )

@tkdrob
Copy link
Contributor

tkdrob commented Aug 17, 2022

#76919 also possibly solved

@bdraco
Copy link
Member Author

bdraco commented Aug 17, 2022

I'm pretty sure this will fix it, but I'm not comfortable merging it without adding some more tests since we are obviously lacking ones to catch this case in the first place.

That might have to be tomorrow though

@bdraco
Copy link
Member Author

bdraco commented Aug 17, 2022

Need to step away for a bit since I've been sitting for too long. I'll write tests when I get back.

@bdraco
Copy link
Member Author

bdraco commented Aug 18, 2022

    hass.async_create_task(
        discovery.async_load_platform(
            hass,
            Platform.NOTIFY,
            DOMAIN,
            hass.data[DOMAIN][entry.entry_id],
            hass.data[DOMAIN],
        )
    )
    hass.async_create_task(
        discovery.async_load_platform(
            hass,
            Platform.NOTIFY,
            DOMAIN,
            hass.data[DOMAIN][entry.entry_id],
            hass.data[DOMAIN],
        )
    )

@tkdrob
Copy link
Contributor

tkdrob commented Aug 18, 2022

Pulled this PR and ran local tests with changes from #76959 and #76960. Things are looking good.

@bdraco bdraco marked this pull request as ready for review August 18, 2022 01:39
@bdraco bdraco requested a review from a team as a code owner August 18, 2022 01:39
Copy link
Member

@balloob balloob left a comment

Choose a reason for hiding this comment

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

This is an improvement as it could race. Not sure if it is the issue though. I think the forwarding not real hass_config to discovery is the real cause.

@balloob balloob merged commit 03fac0c into home-assistant:dev Aug 18, 2022
@tkdrob
Copy link
Contributor

tkdrob commented Aug 18, 2022

This is an improvement as it could race. Not sure if it is the issue though. I think the forwarding not real hass_config to discovery is the real cause.

This may be true except that nfandroidtv was passing correctly yet was reported with the same issue. Like Nick has told me, it's a very narrow window. People who ran into this were very unlucky.

balloob pushed a commit that referenced this pull request Aug 18, 2022
@balloob balloob mentioned this pull request Aug 18, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Aug 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
5 participants