Skip to content

Commit

Permalink
Add OpenSSL::SSL::SSLError to http connection errors wrapper (masto…
Browse files Browse the repository at this point in the history
  • Loading branch information
mjankowski authored Oct 8, 2024
1 parent e8ec666 commit 258dce1
Show file tree
Hide file tree
Showing 19 changed files with 22 additions and 21 deletions.
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ApplicationController < ActionController::Base
rescue_from ActionController::InvalidAuthenticityToken, with: :unprocessable_entity
rescue_from Mastodon::RateLimitExceededError, with: :too_many_requests

rescue_from(*Mastodon::HTTP_CONNECTION_ERRORS, OpenSSL::SSL::SSLError, with: :internal_server_error)
rescue_from(*Mastodon::HTTP_CONNECTION_ERRORS, with: :internal_server_error)
rescue_from Mastodon::RaceConditionError, Stoplight::Error::RedLight, ActiveRecord::SerializationFailure, with: :service_unavailable

rescue_from Seahorse::Client::NetworkingError do |e|
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/concerns/signature_verification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def signed_request_actor
fail_with! "Verification failed for #{actor.to_log_human_identifier} #{actor.uri} using rsa-sha256 (RSASSA-PKCS1-v1_5 with SHA-256)", signed_string: compare_signed_string, signature: signature_params['signature']
rescue SignatureVerificationError => e
fail_with! e.message
rescue *Mastodon::HTTP_CONNECTION_ERRORS, OpenSSL::SSL::SSLError => e
rescue *Mastodon::HTTP_CONNECTION_ERRORS => e
fail_with! "Failed to fetch remote data: #{e.message}"
rescue Mastodon::UnexpectedResponseError
fail_with! 'Failed to fetch remote data (got unexpected reply from server)'
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/media_proxy_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class MediaProxyController < ApplicationController
rescue_from ActiveRecord::RecordInvalid, with: :not_found
rescue_from Mastodon::UnexpectedResponseError, with: :not_found
rescue_from Mastodon::NotPermittedError, with: :not_found
rescue_from(*Mastodon::HTTP_CONNECTION_ERRORS, OpenSSL::SSL::SSLError, with: :internal_server_error)
rescue_from(*Mastodon::HTTP_CONNECTION_ERRORS, with: :internal_server_error)

def show
with_redis_lock("media_download:#{params[:id]}") do
Expand Down
4 changes: 2 additions & 2 deletions app/lib/activitypub/activity/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def process_mention(tag)
return if account.nil?

@mentions << Mention.new(account: account, silent: false)
rescue Mastodon::UnexpectedResponseError, *Mastodon::HTTP_CONNECTION_ERRORS, OpenSSL::SSL::SSLError
rescue Mastodon::UnexpectedResponseError, *Mastodon::HTTP_CONNECTION_ERRORS
@unresolved_mentions << tag['href']
end

Expand Down Expand Up @@ -250,7 +250,7 @@ def process_attachments
media_attachment.download_file!
media_attachment.download_thumbnail!
media_attachment.save
rescue Mastodon::UnexpectedResponseError, *Mastodon::HTTP_CONNECTION_ERRORS, OpenSSL::SSL::SSLError
rescue Mastodon::UnexpectedResponseError, *Mastodon::HTTP_CONNECTION_ERRORS
RedownloadMediaWorker.perform_in(rand(30..600).seconds, media_attachment.id)
rescue Seahorse::Client::NetworkingError => e
Rails.logger.warn "Error storing media attachment: #{e}"
Expand Down
2 changes: 1 addition & 1 deletion app/models/account_alias.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def pretty_acct
def set_uri
target_account = ResolveAccountService.new.call(acct)
self.uri = ActivityPub::TagManager.instance.uri_for(target_account) unless target_account.nil?
rescue Webfinger::Error, *Mastodon::HTTP_CONNECTION_ERRORS, OpenSSL::SSL::SSLError, Mastodon::Error
rescue Webfinger::Error, *Mastodon::HTTP_CONNECTION_ERRORS, Mastodon::Error
# Validation will take care of it
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/account_migration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def cooldown_at

def set_target_account
self.target_account = ResolveAccountService.new.call(acct, skip_cache: true)
rescue Webfinger::Error, *Mastodon::HTTP_CONNECTION_ERRORS, OpenSSL::SSL::SSLError, Mastodon::Error, Addressable::URI::InvalidURIError
rescue Webfinger::Error, *Mastodon::HTTP_CONNECTION_ERRORS, Mastodon::Error, Addressable::URI::InvalidURIError
# Validation will take care of it
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/concerns/remotable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def remotable_attachment(attachment_name, limit, suppress_errors: true, download

public_send(:"#{attachment_name}=", ResponseWithLimit.new(response, limit))
end
rescue Mastodon::UnexpectedResponseError, *Mastodon::HTTP_CONNECTION_ERRORS, OpenSSL::SSL::SSLError => e
rescue Mastodon::UnexpectedResponseError, *Mastodon::HTTP_CONNECTION_ERRORS => e
Rails.logger.debug { "Error fetching remote #{attachment_name}: #{e}" }
public_send(:"#{attachment_name}=", nil) if public_send(:"#{attachment_name}_file_name").present?
raise e unless suppress_errors
Expand Down
2 changes: 1 addition & 1 deletion app/models/form/redirect.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def acct=(val)

def set_target_account
@target_account = ResolveAccountService.new.call(acct, skip_cache: true)
rescue Webfinger::Error, *Mastodon::HTTP_CONNECTION_ERRORS, OpenSSL::SSL::SSLError, Mastodon::Error, Addressable::URI::InvalidURIError
rescue Webfinger::Error, *Mastodon::HTTP_CONNECTION_ERRORS, Mastodon::Error, Addressable::URI::InvalidURIError
# Validation will take care of it
end

Expand Down
6 changes: 3 additions & 3 deletions app/services/activitypub/process_account_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,13 @@ def set_fetchable_attributes!
begin
@account.avatar_remote_url = image_url('icon') || '' unless skip_download?
@account.avatar = nil if @account.avatar_remote_url.blank?
rescue Mastodon::UnexpectedResponseError, *Mastodon::HTTP_CONNECTION_ERRORS, OpenSSL::SSL::SSLError
rescue Mastodon::UnexpectedResponseError, *Mastodon::HTTP_CONNECTION_ERRORS
RedownloadAvatarWorker.perform_in(rand(30..600).seconds, @account.id)
end
begin
@account.header_remote_url = image_url('image') || '' unless skip_download?
@account.header = nil if @account.header_remote_url.blank?
rescue Mastodon::UnexpectedResponseError, *Mastodon::HTTP_CONNECTION_ERRORS, OpenSSL::SSL::SSLError
rescue Mastodon::UnexpectedResponseError, *Mastodon::HTTP_CONNECTION_ERRORS
RedownloadHeaderWorker.perform_in(rand(30..600).seconds, @account.id)
end
@account.statuses_count = outbox_total_items if outbox_total_items.present?
Expand Down Expand Up @@ -276,7 +276,7 @@ def collection_info(type)
total_items = collection.is_a?(Hash) && collection['totalItems'].present? && collection['totalItems'].is_a?(Numeric) ? collection['totalItems'] : nil
has_first_page = collection.is_a?(Hash) && collection['first'].present?
@collections[type] = [total_items, has_first_page]
rescue *Mastodon::HTTP_CONNECTION_ERRORS, OpenSSL::SSL::SSLError, Mastodon::LengthValidationError
rescue *Mastodon::HTTP_CONNECTION_ERRORS, Mastodon::LengthValidationError
@collections[type] = [nil, nil]
end

Expand Down
2 changes: 1 addition & 1 deletion app/services/activitypub/process_status_update_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def download_media_files!
media_attachment.download_file! if media_attachment.remote_url_previously_changed?
media_attachment.download_thumbnail! if media_attachment.thumbnail_remote_url_previously_changed?
media_attachment.save
rescue Mastodon::UnexpectedResponseError, *Mastodon::HTTP_CONNECTION_ERRORS, OpenSSL::SSL::SSLError
rescue Mastodon::UnexpectedResponseError, *Mastodon::HTTP_CONNECTION_ERRORS
RedownloadMediaWorker.perform_in(rand(30..600).seconds, media_attachment.id)
rescue Seahorse::Client::NetworkingError => e
Rails.logger.warn "Error storing media attachment: #{e}"
Expand Down
2 changes: 1 addition & 1 deletion app/services/fetch_link_card_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def call(status)
end

attach_card if @card&.persisted?
rescue *Mastodon::HTTP_CONNECTION_ERRORS, OpenSSL::SSL::SSLError, Addressable::URI::InvalidURIError, Mastodon::HostValidationError, Mastodon::LengthValidationError, Encoding::UndefinedConversionError, ActiveRecord::RecordInvalid => e
rescue *Mastodon::HTTP_CONNECTION_ERRORS, Addressable::URI::InvalidURIError, Mastodon::HostValidationError, Mastodon::LengthValidationError, Encoding::UndefinedConversionError, ActiveRecord::RecordInvalid => e
Rails.logger.debug { "Error fetching link #{@original_url}: #{e}" }
nil
end
Expand Down
2 changes: 1 addition & 1 deletion app/services/fetch_resource_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def call(url)
return if url.blank?

process(url)
rescue *Mastodon::HTTP_CONNECTION_ERRORS, OpenSSL::SSL::SSLError, Addressable::URI::InvalidURIError, Mastodon::HostValidationError, Mastodon::LengthValidationError => e
rescue *Mastodon::HTTP_CONNECTION_ERRORS, Addressable::URI::InvalidURIError, Mastodon::HostValidationError, Mastodon::LengthValidationError => e
Rails.logger.debug { "Error fetching resource #{@url}: #{e}" }
nil
end
Expand Down
2 changes: 1 addition & 1 deletion app/services/import_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def import_bookmarks!
next if status.nil? && ActivityPub::TagManager.instance.local_uri?(uri)

status || ActivityPub::FetchRemoteStatusService.new.call(uri)
rescue *Mastodon::HTTP_CONNECTION_ERRORS, OpenSSL::SSL::SSLError, Mastodon::UnexpectedResponseError
rescue *Mastodon::HTTP_CONNECTION_ERRORS, Mastodon::UnexpectedResponseError
nil
rescue => e
Rails.logger.warn "Unexpected error when importing bookmark: #{e}"
Expand Down
2 changes: 1 addition & 1 deletion app/services/process_mentions_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def scan_text!
if mention_undeliverable?(mentioned_account)
begin
mentioned_account = ResolveAccountService.new.call(Regexp.last_match(1))
rescue Webfinger::Error, *Mastodon::HTTP_CONNECTION_ERRORS, OpenSSL::SSL::SSLError, Mastodon::UnexpectedResponseError
rescue Webfinger::Error, *Mastodon::HTTP_CONNECTION_ERRORS, Mastodon::UnexpectedResponseError
mentioned_account = nil
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/services/software_update_check_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def fetch_update_notices
Request.new(:get, "#{api_url}?version=#{version}").add_headers('Accept' => 'application/json', 'User-Agent' => 'Mastodon update checker').perform do |res|
return Oj.load(res.body_with_limit, mode: :strict) if res.code == 200
end
rescue *Mastodon::HTTP_CONNECTION_ERRORS, OpenSSL::SSL::SSLError, Oj::ParseError
rescue *Mastodon::HTTP_CONNECTION_ERRORS, Oj::ParseError
nil
end

Expand Down
2 changes: 1 addition & 1 deletion app/services/verify_link_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def call(field)
return unless link_back_present?

field.mark_verified!
rescue OpenSSL::SSL::SSLError, *Mastodon::HTTP_CONNECTION_ERRORS, Addressable::URI::InvalidURIError, Mastodon::HostValidationError, Mastodon::LengthValidationError, IPAddr::AddressFamilyError => e
rescue *Mastodon::HTTP_CONNECTION_ERRORS, Addressable::URI::InvalidURIError, Mastodon::HostValidationError, Mastodon::LengthValidationError, IPAddr::AddressFamilyError => e
Rails.logger.debug { "Error fetching link #{@url}: #{e}" }
nil
end
Expand Down
2 changes: 1 addition & 1 deletion app/workers/refollow_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def perform(target_account_id)
# Schedule re-follow
begin
FollowService.new.call(follower, target_account, reblogs: reblogs, notify: notify, languages: languages, bypass_limit: true)
rescue Mastodon::NotPermittedError, ActiveRecord::RecordNotFound, Mastodon::UnexpectedResponseError, *Mastodon::HTTP_CONNECTION_ERRORS, OpenSSL::SSL::SSLError
rescue Mastodon::NotPermittedError, ActiveRecord::RecordNotFound, Mastodon::UnexpectedResponseError, *Mastodon::HTTP_CONNECTION_ERRORS
next
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@ def initialize(host)
HTTP::ConnectionError,
HTTP::Error,
HTTP::TimeoutError,
OpenSSL::SSL::SSLError,
].freeze
end
2 changes: 1 addition & 1 deletion lib/mastodon/cli/accounts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ def cull(*domains)

begin
code = Request.new(:head, account.uri).perform(&:code)
rescue *Mastodon::HTTP_CONNECTION_ERRORS, OpenSSL::SSL::SSLError, Mastodon::PrivateNetworkAddressError
rescue *Mastodon::HTTP_CONNECTION_ERRORS, Mastodon::PrivateNetworkAddressError
skip_domains << account.domain
end

Expand Down

0 comments on commit 258dce1

Please sign in to comment.