From e2059cfc5b9b8330c317da417366d1e7c76cccc7 Mon Sep 17 00:00:00 2001 From: Sojan Jose Date: Tue, 8 Nov 2022 20:23:46 -0800 Subject: [PATCH] fix: SocketError: getaddrinfo: for imap channels (#5824) fixes: #5431 --- app/jobs/inboxes/fetch_imap_emails_job.rb | 2 +- lib/exception_list.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/jobs/inboxes/fetch_imap_emails_job.rb b/app/jobs/inboxes/fetch_imap_emails_job.rb index 9f69f32d7..c4537ca22 100644 --- a/app/jobs/inboxes/fetch_imap_emails_job.rb +++ b/app/jobs/inboxes/fetch_imap_emails_job.rb @@ -9,7 +9,7 @@ class Inboxes::FetchImapEmailsJob < ApplicationJob fetch_mail_for_channel(channel) # clearing old failures like timeouts since the mail is now successfully processed channel.reauthorized! - rescue Errno::ECONNREFUSED, Net::OpenTimeout, Net::IMAP::NoResponseError, Errno::ECONNRESET, Errno::ENETUNREACH, Net::IMAP::ByeResponseError + rescue *ExceptionList::IMAP_EXCEPTIONS channel.authorization_error! rescue EOFError => e Rails.logger.error e diff --git a/lib/exception_list.rb b/lib/exception_list.rb index 4aafdec15..fccc747c6 100644 --- a/lib/exception_list.rb +++ b/lib/exception_list.rb @@ -1,3 +1,5 @@ +require 'net/imap' + module ExceptionList REST_CLIENT_EXCEPTIONS = [RestClient::NotFound, RestClient::GatewayTimeout, RestClient::BadRequest, RestClient::MethodNotAllowed, RestClient::Forbidden, RestClient::InternalServerError, @@ -8,4 +10,10 @@ module ExceptionList SMTP_EXCEPTIONS = [ Net::SMTPSyntaxError ].freeze + + IMAP_EXCEPTIONS = [ + Errno::ECONNREFUSED, Net::OpenTimeout, Net::IMAP::NoResponseError, + Errno::ECONNRESET, Errno::ENETUNREACH, Net::IMAP::ByeResponseError, + SocketError + ].freeze end