From 3fb6a9e0bff75761d59bbd5bb83408231586ef25 Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Sat, 16 Nov 2024 21:53:18 +1300 Subject: [PATCH] increase http post timeout to 10 seconds --- app/community/routes.py | 2 +- app/community/util.py | 2 +- app/post/routes.py | 12 ++++++------ 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/community/routes.py b/app/community/routes.py index 31395e8b..8d202179 100644 --- a/app/community/routes.py +++ b/app/community/routes.py @@ -838,7 +838,7 @@ def federate_post(community, post): page['oneOf' if poll.mode == 'single' else 'anyOf'] = choices if not community.is_local(): # this is a remote community - send the post to the instance that hosts it post_request_in_background(community.ap_inbox_url, create, current_user.private_key, - current_user.public_url() + '#main-key') + current_user.public_url() + '#main-key', timeout=10) flash(_('Your post to %(name)s has been made.', name=community.title)) else: # local community - send (announce) post out to followers announce = { diff --git a/app/community/util.py b/app/community/util.py index 7f236e6a..36f3363d 100644 --- a/app/community/util.py +++ b/app/community/util.py @@ -739,7 +739,7 @@ def send_to_remote_instance_task(instance_id: int, community_id: int, payload): if community: instance: Instance = session.query(Instance).get(instance_id) if instance.inbox and instance.online() and not instance_banned(instance.domain): - if post_request(instance.inbox, payload, community.private_key, community.ap_profile_id + '#main-key') is True: + if post_request(instance.inbox, payload, community.private_key, community.ap_profile_id + '#main-key', timeout=10) is True: instance.last_successful_send = utcnow() instance.failures = 0 else: diff --git a/app/post/routes.py b/app/post/routes.py index ab9bacf5..47180992 100644 --- a/app/post/routes.py +++ b/app/post/routes.py @@ -133,8 +133,8 @@ def show_post(post_id: int): }] } if not community.is_local(): # this is a remote community, send it to the instance that hosts it - success = post_request(community.ap_inbox_url, create_json, current_user.private_key, - current_user.public_url() + '#main-key') + success = post_request_in_background(community.ap_inbox_url, create_json, current_user.private_key, + current_user.public_url() + '#main-key', timeout=10) if success is False or isinstance(success, str): flash('Failed to send to remote instance', 'error') else: # local community - send it to followers on remote instances @@ -159,13 +159,13 @@ def show_post(post_id: int): # send copy of Note to post author (who won't otherwise get it if no-one else on their instance is subscribed to the community) if not post.author.is_local() and post.author.ap_domain != community.ap_domain: if not community.is_local() or (community.is_local and not community.has_followers_from_domain(post.author.ap_domain)): - success = post_request(post.author.ap_inbox_url, create_json, current_user.private_key, - current_user.public_url() + '#main-key') + success = post_request_in_background(post.author.ap_inbox_url, create_json, current_user.private_key, + current_user.public_url() + '#main-key', timeout=10) if success is False or isinstance(success, str): # sending to shared inbox is good enough for Mastodon, but Lemmy will reject it the local community has no followers personal_inbox = post.author.public_url() + '/inbox' - post_request(personal_inbox, create_json, current_user.private_key, - current_user.public_url() + '#main-key') + post_request_in_background(personal_inbox, create_json, current_user.private_key, + current_user.public_url() + '#main-key', timeout=10) return redirect(url_for('activitypub.post_ap', post_id=post_id, _anchor=f'comment_{reply.id}')) else: