From aee89ca8c93906d9d608444aa0b61261b8f2d144 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 24 Apr 2022 20:03:02 +0100 Subject: [PATCH] Timeout when getting rss feeds --- daemon.py | 3 +++ epicyon.py | 3 ++- newsdaemon.py | 3 ++- newswire.py | 13 +++++++++---- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/daemon.py b/daemon.py index 88009d8bd..02892de67 100644 --- a/daemon.py +++ b/daemon.py @@ -20804,6 +20804,9 @@ def run_daemon(preferred_podcast_formats: [], 'Reminder': 'r' } + # timeout used when getting rss feeds + httpd.rss_timeout_sec = 20 + # timeout used when checking for actor changes when clicking an avatar # and entering person options screen if check_actor_timeout < 2: diff --git a/epicyon.py b/epicyon.py index 034ae5b77..67073ce82 100644 --- a/epicyon.py +++ b/epicyon.py @@ -1162,10 +1162,11 @@ if podcast_formats_str: preferred_podcast_formats.append(pod_format) if args.rss: + timeout_sec = 20 session = create_session(None) testRSS = get_rss(base_dir, domain, session, args.rss, False, False, 1000, 1000, 1000, 1000, debug, - preferred_podcast_formats) + preferred_podcast_formats, timeout_sec) pprint(testRSS) sys.exit() diff --git a/newsdaemon.py b/newsdaemon.py index 4ec7e0b1c..5bf8ab115 100644 --- a/newsdaemon.py +++ b/newsdaemon.py @@ -818,7 +818,8 @@ def run_newswire_daemon(base_dir: str, httpd, httpd.maxCategoriesFeedItemSizeKb, httpd.system_language, httpd.debug, - httpd.preferred_podcast_formats) + httpd.preferred_podcast_formats, + httpd.rss_timeout_sec) if not httpd.newswire: print('Newswire feeds not updated') diff --git a/newswire.py b/newswire.py index 65c3d2302..748425c4e 100644 --- a/newswire.py +++ b/newswire.py @@ -1278,7 +1278,8 @@ def get_rss(base_dir: str, domain: str, session, url: str, max_posts_per_source: int, max_feed_size_kb: int, max_feed_item_size_kb: int, max_categories_feedItem_size_kb: int, debug: bool, - preferred_podcast_formats: []) -> {}: + preferred_podcast_formats: [], + timeout_sec: int) -> {}: """Returns an RSS url as a dict """ if not isinstance(url, str): @@ -1302,7 +1303,9 @@ def get_rss(base_dir: str, domain: str, session, url: str, url = _yt_channel_to_atom_feed(url) try: result = \ - session.get(url, headers=session_headers, params=session_params) + session.get(url, headers=session_headers, + params=session_params, + timeout=timeout_sec) if result: if int(len(result.text) / 1024) < max_feed_size_kb and \ not contains_invalid_chars(result.text): @@ -1558,7 +1561,8 @@ def get_dict_from_newswire(session, base_dir: str, domain: str, max_newswire_posts: int, max_categories_feedItem_size_kb: int, system_language: str, debug: bool, - preferred_podcast_formats: []) -> {}: + preferred_podcast_formats: [], + timeout_sec: int) -> {}: """Gets rss feeds as a dictionary from newswire file """ subscriptions_filename = base_dir + '/accounts/newswire.txt' @@ -1600,7 +1604,8 @@ def get_dict_from_newswire(session, base_dir: str, domain: str, max_posts_per_source, max_feed_size_kb, max_feed_item_size_kb, max_categories_feedItem_size_kb, debug, - preferred_podcast_formats) + preferred_podcast_formats, + timeout_sec) if items_list: for date_str, item in items_list.items(): result[date_str] = item