-
Notifications
You must be signed in to change notification settings - Fork 304
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
[Workaround Patch Available] Blocking call in aiohttp CookieJar causing stability issues #2520
Comments
@danielbrunt57 FYI |
@jleinenbach See aio-libs/aiohttp#9430 and @bdraco's comments. |
@jleinenbach BTW, your solution in cookiejar.py would still block the event loop even though HA fails to detect it:
|
See |
Describe the bug
The
alexa_media
integration is causing blocking calls within the event loop due to synchronous file operations inaiohttp.cookiejar.CookieJar
. Specifically, the methodssave
andload
inCookieJar
perform synchronous file I/O operations, leading to stability issues in Home Assistant and generating warnings about blocking calls toopen
.To Reproduce
alexa_media
integration in Home Assistant.And:
Expected behavior
Asynchronous operations should not perform blocking file I/O within the event loop. The integration should avoid blocking calls to maintain stability in Home Assistant.
Screenshots
N/A
System details
alexa_media
version (fromconst.py
or HA startup log): e.g., 4.12.12alexapy
version (frompip show alexapy
in Home Assistant container or HA startup log): e.g., 1.29.2Debug Logs (alexa_media & alexapy)
Additional similar error during cookie loading:
Additional context
Please find the adjusted
cookiejar.py
file attached or consider integrating similar changes to address the issue.You can apply this patch by:
Install the Patch integration with HACS.
Download the
cookiejar-patched.py.txt
file, rename it tocookiejar.py
, and place it in aconfig/patches/aiohttp/3.10.5/patch
directory.Copy the original
/usr/local/lib/python3.12/site-packages/aiohttp/cookiejar.py
toconfig/patches/aiohttp/3.10.5/base
.Then add this to your
configuration.yaml
:This workaround modifies the
cookiejar.py
file to offload blocking file operations to a separate thread and ensures synchronization usingthreading.Event
. This allows the methods to remain synchronous from the caller's perspective, avoiding changes toalexapy
oralexa_media
.Proposed Solution
Implement the adjusted
cookiejar.py
to resolve the blocking call issue. The key changes include:save
andload
methods to separate threads usingrun_in_executor
.threading.Event
to wait for the completion of loading and saving operations.self._cookies
wait until the cookies are fully loaded.This adjustment prevents the event loop from being blocked by synchronous file operations and maintains compatibility with existing code that relies on
aiohttp.cookiejar.CookieJar
.Note: While this workaround resolves the immediate problem, a long-term solution would involve updating
aiohttp
to handle cookie file operations asynchronously or adjustingalexapy
andalexa_media
to avoid blocking calls within the event loop.Additionally, if this workaround proves effective, it would be beneficial for someone to open an issue on the aiohttp GitHub repository to address this problem.
The text was updated successfully, but these errors were encountered: