Use asyncio.to_thread for blocking manifest fetch in async endpoint
The /api/update-check endpoint is async but fetch_and_cache_update_status performs a blocking HTTP request via urllib. Wrap it in asyncio.to_thread to avoid blocking the FastAPI event loop when the background thread has not yet completed the initial fetch.
This commit is contained in:
parent
7bca7bf0db
commit
6b843a8e8e
1 changed files with 4 additions and 1 deletions
|
|
@ -230,7 +230,10 @@ async def update_check():
|
|||
s = get_update_status()
|
||||
if not s.manifest_fetched:
|
||||
# Background thread may not have finished yet -- fetch inline.
|
||||
s = fetch_and_cache_update_status()
|
||||
# Run in a thread to avoid blocking the async event loop.
|
||||
import asyncio
|
||||
|
||||
s = await asyncio.to_thread(fetch_and_cache_update_status)
|
||||
return {
|
||||
"critical": s.critical,
|
||||
"announcement_badge": s.announcement_badge,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue