From 560c06463d1954b9d7bbd6080013de092b682117 Mon Sep 17 00:00:00 2001 From: Jeremy Kescher Date: Sun, 15 Jan 2023 21:19:41 +0100 Subject: [PATCH] Check for instance availability before attempting to fetch mentioned users Port of https://github.com/Snailed-It/mastodon/commit/db6b0a3b5d3d81db7a534f99d7607c7f46ae4a8c and https://github.com/Snailed-It/mastodon/commit/d59d1d472e5d915ee998f7c499f1205dcb899c91. Full credit goes to dwrss on GitHub. Does NOT fix https://github.com/mastodon/mastodon/issues/22713. --- app/lib/activitypub/activity/create.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/lib/activitypub/activity/create.rb b/app/lib/activitypub/activity/create.rb index 4dfbfc6658..c41d310db5 100644 --- a/app/lib/activitypub/activity/create.rb +++ b/app/lib/activitypub/activity/create.rb @@ -222,8 +222,13 @@ class ActivityPub::Activity::Create < ActivityPub::Activity return if tag['href'].blank? account = account_from_uri(tag['href']) - account = ActivityPub::FetchRemoteAccountService.new.call(tag['href'], request_id: @options[:request_id]) if account.nil? - + begin + return unless account || DeliveryFailureTracker.available?(tag['href']) + account = ActivityPub::FetchRemoteAccountService.new.call(tag['href'], request_id: @options[:request_id]) if account.nil? + rescue HTTP::ConnectionError => e + Rails.logger.info "Fetching account #{tag['href']} failed: #{e}" + raise + end return if account.nil? @mentions << Mention.new(account: account, silent: false)