-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
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 timing issue in Withings #105203
Fix timing issue in Withings #105203
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can register_webhook
raise an exception e.g. while communicating with a cloud api? It may require setting/unsetting this with some exception handling. If so, then consider adding another wrapper function to manage the lock. (or maybe route all calls through manage_cloudhook
and put the lock in that function.)
Well the problem I have is that the user disconnects from cloud for a 3 seconds, so both the register and unregister process is running. I think I can solve this by putting the same lock on those functions, not sure what's bvest |
This doesn't seem to handle register and unregister running at the same time? Seems like it just prevents register from running twice at once? There are some problematic cases to worry about for something like this:
That is problematic because an unregister task may arrive while register is running and it's not necessarily correct to just drop it on the floor. You can put a lock on both operations like this:
Then if an unregister task arrives while the register task is running then it will queue and wait for the register task to finish. This may also mean that register/unregister tasks pile up though. I also am not sure if they necessarily run in a specific order (e.g. if multiple register tasks or unregister tasks are waiting, does the lock "wake up" in a specific order they arrived in? Probably not necessarily...) Another approach can be any time a task is invoked it decides what to do once it actually runs based on the current state, or exits early or no-op if things are already in the proper state e.g.
I may be missing some details here, but broadly those are approaches that come to mind. |
I will create tests for this in a follow up. Since the tests are encountering locks, I need some more time for this and don't want to hold up the fix. This has been tested with several people. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's take this route to get the "fix" out, but we should seriously considering extracting this to get rid of nonlocals
and incoperate some feedback from Allen above.
Proposed change
Fix timing issue in Withings
Type of change
Additional information
Checklist
ruff format homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
..coveragerc
.To help with the load of incoming pull requests: