increase http post timeout to 10 seconds

This commit is contained in:
rimu 2024-11-16 21:53:18 +13:00
parent d5ae01b456
commit 3fb6a9e0bf
3 changed files with 8 additions and 8 deletions

View file

@ -838,7 +838,7 @@ def federate_post(community, post):
page['oneOf' if poll.mode == 'single' else 'anyOf'] = choices 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 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, 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)) flash(_('Your post to %(name)s has been made.', name=community.title))
else: # local community - send (announce) post out to followers else: # local community - send (announce) post out to followers
announce = { announce = {

View file

@ -739,7 +739,7 @@ def send_to_remote_instance_task(instance_id: int, community_id: int, payload):
if community: if community:
instance: Instance = session.query(Instance).get(instance_id) instance: Instance = session.query(Instance).get(instance_id)
if instance.inbox and instance.online() and not instance_banned(instance.domain): 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.last_successful_send = utcnow()
instance.failures = 0 instance.failures = 0
else: else:

View file

@ -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 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, success = post_request_in_background(community.ap_inbox_url, create_json, current_user.private_key,
current_user.public_url() + '#main-key') current_user.public_url() + '#main-key', timeout=10)
if success is False or isinstance(success, str): if success is False or isinstance(success, str):
flash('Failed to send to remote instance', 'error') flash('Failed to send to remote instance', 'error')
else: # local community - send it to followers on remote instances 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) # 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 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)): 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, success = post_request_in_background(post.author.ap_inbox_url, create_json, current_user.private_key,
current_user.public_url() + '#main-key') current_user.public_url() + '#main-key', timeout=10)
if success is False or isinstance(success, str): 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 # 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' personal_inbox = post.author.public_url() + '/inbox'
post_request(personal_inbox, create_json, current_user.private_key, post_request_in_background(personal_inbox, create_json, current_user.private_key,
current_user.public_url() + '#main-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}')) return redirect(url_for('activitypub.post_ap', post_id=post_id, _anchor=f'comment_{reply.id}'))
else: else: