Fix server freeze from unresponsive logo/image hosts

requests.get() calls had no timeout and ran directly on the aiohttp
event loop, so a single dead logo host would hang for minutes and
block every other request. Add timeouts and move logo downloads in
get_logo to a thread executor so a slow/dead host no longer stalls
the whole server.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
ubuntu
2026-08-30 18:05:19 +00:00
co-authored by Claude Sonnet 5
parent df36139bd5
commit b16a0a811c
+5 -5
View File
@@ -359,7 +359,7 @@ def make_xtream_series_channels(id_playlist, series_item, series_info, category_
def save_image_from_url(url, save_path):
try:
# Send a GET request to the URL
response = requests.get(url)
response = requests.get(url, timeout=10)
response.raise_for_status() # Raise an error for unsuccessful status codes
# Write the content of the response to a file
@@ -1059,7 +1059,7 @@ def get_image_urls(keyword, max_results=10):
}
# Send the search request
response = requests.get(search_url, headers=headers)
response = requests.get(search_url, headers=headers, timeout=10)
soup = BeautifulSoup(response.text, 'html.parser')
# Find image containers
@@ -1096,14 +1096,14 @@ async def get_logo(request):
if l :
url_logo = l['logo_url']
print('url trouvée : ' + url_logo, flush=True)
save_image_from_url(url_logo, logo_channel_file_path)
await asyncio.get_running_loop().run_in_executor(None, save_image_from_url, url_logo, logo_channel_file_path)
query = { 'id_channel':id_channel}
update = { "$set": { "urlLogo": url_logo } }
collection_channels.update_one(query, update)
else:
print('url identifiee et sauvegarde du fichier : ' + url_logo, flush=True)
if len(url_logo) > 0:
save_image_from_url(url_logo, logo_channel_file_path)
await asyncio.get_running_loop().run_in_executor(None, save_image_from_url, url_logo, logo_channel_file_path)
image_data = None
if not os.path.exists(logo_channel_file_path):
@@ -1373,7 +1373,7 @@ async def download_epg(request):
filename = data['filename']
filepath = os.path.join(DOWNLOAD_EPG_DIR, filename)
print('download file :', url, flush=True)
response = requests.get(url)
response = requests.get(url, timeout=10)
with open(filepath, 'wb') as f:
f.write(response.content)
return web.json_response({'status':'ok'})