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

Fix Intellifire UDP timeout #80204

Merged
merged 4 commits into from
Oct 15, 2022
Merged

Conversation

jeeftor
Copy link
Contributor

@jeeftor jeeftor commented Oct 12, 2022

Proposed change

Update the backing library to version 2.2.1 which uses a correct UDP timeout value for socket receive. It will return an empty discovery list upon timeout - which will then let the user enter an IP of their choice:

image

All changes can be seen here:
jeeftor/intellifire4py@2.0.1...2.2.1

I've rewritten the AsyncUDPFireplaceFinder class to utilize asyncio.create_datagram_endpoint which hopefully will fix the existing bug we ran into.

Timeout for fireplace discovery is now changed to 12 seconds.

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

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:

@jeeftor jeeftor changed the title Intellifire Version Bump Intellifire Version Bump / UDP Timeout bug fix Oct 12, 2022
@jeeftor jeeftor force-pushed the intellifire_udp_bug branch from a84d1d6 to 54427b7 Compare October 12, 2022 20:15
@jeeftor jeeftor force-pushed the intellifire_udp_bug branch from 54427b7 to f94bc50 Compare October 12, 2022 20:15
@jeeftor jeeftor marked this pull request as ready for review October 12, 2022 20:16
@bdraco
Copy link
Member

bdraco commented Oct 12, 2022

It looks like the library is doing blocking recv aka I/O in jeeftor/intellifire4py@2.0.1...2.1.1#diff-fc920c359ade158eaf9781217560dc1d6cb5ad59038a88f3ed5c116b8ecbb80bR61

Ideally this would get converted to an asyncio.Protocol and you can use loop.create_datagram_endpoint()

@jeeftor
Copy link
Contributor Author

jeeftor commented Oct 12, 2022

@bdraco - you are a wealth of knowledge... I'll look into how to do that :)

@jeeftor
Copy link
Contributor Author

jeeftor commented Oct 12, 2022

That being said - in the short term -> Think we could still get this patch in to the core - so I can help a user who can't install the integration because their network is doing something to UDP traffic?

@bdraco
Copy link
Member

bdraco commented Oct 12, 2022

That being said - in the short term -> Think we could still get this patch in to the core - so I can help a user who can't install the integration because their network is doing something to UDP traffic?

I think there is a much larger risk of blocking the event loop since if the recvfrom does end up blocking its going to be for up to 15s (or longer)

Here are few examples you can borrow

https://github.com/bdraco/discovery30303/blob/master/discovery30303/__init__.py

or something more complex:
https://github.com/Danielhiversen/flux_led/blob/master/flux_led/aioscanner.py

@bdraco
Copy link
Member

bdraco commented Oct 12, 2022

The screen logic and unifi-discovery libraries have more examples as well

@MartinHjelmare MartinHjelmare changed the title Intellifire Version Bump / UDP Timeout bug fix Fix Intellifire UDP timeout Oct 13, 2022
@jeeftor
Copy link
Contributor Author

jeeftor commented Oct 13, 2022

@bdraco - Thanks for the pointers. I believe I have it using asyncio fully

@jeeftor jeeftor marked this pull request as draft October 13, 2022 18:44
@jeeftor jeeftor marked this pull request as ready for review October 13, 2022 19:09
@jeeftor jeeftor force-pushed the intellifire_udp_bug branch from 356a38f to e58be42 Compare October 15, 2022 15:02
Copy link
Member

@bdraco bdraco left a comment

Choose a reason for hiding this comment

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

Thanks 👍

@bdraco bdraco added this to the 2022.10.5 milestone Oct 15, 2022
@bdraco
Copy link
Member

bdraco commented Oct 15, 2022

@jeeftor Unrelated to this PR, but you can generally switch out asyncio.wait_for with the async_timeout and it will be much faster and less race prone

@bdraco bdraco merged commit 5efc706 into home-assistant:dev Oct 15, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Oct 16, 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.

Intellifire UDP Timeout error - Causing HA to crash
4 participants