-
-
Notifications
You must be signed in to change notification settings - Fork 32k
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
Shield Reolink webhook callback from cancelation #89798
Shield Reolink webhook callback from cancelation #89798
Conversation
Co-authored-by: Paulus Schoutsen <[email protected]>
Seeing something weird in testing (see #89798 (comment)) |
Why is the webhook callback cancelled in the first place?
|
@MartinHjelmare The cancelation originates from somewhere upstream to
My best bet at this moment is that it is simular to what is discribed here:
Further more recent explanation seems to be here: aio-libs/aiohttp#6719 |
@MartinHjelmare I found the answer in the documentation of aiohttp:
So I did implement the correct solution. |
This HomeAssistant PR #88046 implemented the cancallation pollicy in a wrapper untill aiohttp 3.9 is released. @MartinHjelmare core/homeassistant/helpers/aiohttp_compat.py Lines 10 to 15 in a15c45d
|
If a camera drops a connection, the handler is cancelled. That has been the behavior of aiohttp until 3.8.3 changed it, and we put it back until we can make a decision how we want to move forward with this. In this case, the task is lingering because you start it but don't await it – but that's the point 😅 You should run |
@balloob I get it, thanks for the info. |
yeah I guess it's fine. |
Breaking change
Proposed change
Some camera's like the RLC-520A do not (yet) support rich ONVIF notifications that include both motion and AI detection states.
These camera's only send motion pushes.
Therefore when a motion push is received, the AI detection state will be polled inside the async webhook callback which takes between 0.5 and 1.5 seconds on average. This works since a vehicle/pet/person most of the time will also cause a motion event besides the AI detection event.
This is not ideal, but the best we can do on our site (Reolink schould update the firmware to support rich ONVIF notifications).
However since the poll takes 0.5 to 1.5 seconds, the asyncio webhook callback task would get cancelled while waiting on the response, in the upstream library on line:
https://github.com/starkillerOG/reolink_aio/blob/2362257923badb708543643a2f1e3c7bcb07cdb5/reolink_aio/api.py#L3149
response = await self._aiohttp_session.post(url=self._url, json=body, params=param, allow_redirects=False)
This PR shields the callback task, such that it does not get cancelled and the response and further processing of the callback can finish.
Note: it is automatically detected if a camera supports rich ONVIF notifications, if it does, no polling is used inside the webhook callback.
(It took me forever to figure out what was going on, this was a hard bug to solve).
Could this be added to the next milestone?
Type of change
Additional information
Checklist
black --fast 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: