From 656ae41b24c3a7b7a02fd1ea3277d51213c3f78a Mon Sep 17 00:00:00 2001 From: Sojan Jose Date: Sat, 7 Feb 2026 17:30:54 -0800 Subject: [PATCH] fix(imap): handle IMAP parser/read errors without exception tracking (#13473) When an IMAP server returns malformed or partial protocol responses, Inboxes::FetchImapEmailsJob can raise Net::IMAP::ResponseParseError, Net::IMAP::ResponseReadError, or Net::IMAP::ResponseTooLargeError. Previously these errors fell through to the generic StandardError handler and were captured repeatedly in Sentry. This PR updates app/jobs/inboxes/fetch_imap_emails_job.rb to treat those parser/read exceptions as handled IMAP failures by adding them to the existing IMAP/network rescue block, so they are logged and retried on the next scheduled run without exception tracking noise. fixes: https://chatwoot-p3.sentry.io/issues/7132037793/events/104fb9b4d80a4fb6ba3861c44c6c9b83/ How to reproduce: - Use an IMAP server/inbox that intermittently returns malformed or truncated protocol responses during search/fetch. - Run Inboxes::FetchImapEmailsJob for that channel and observe the raised parser/read exception. How this was tested: - bundle exec ruby -c app/jobs/inboxes/fetch_imap_emails_job.rb - bundle exec rubocop app/jobs/inboxes/fetch_imap_emails_job.rb --- app/jobs/inboxes/fetch_imap_emails_job.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/jobs/inboxes/fetch_imap_emails_job.rb b/app/jobs/inboxes/fetch_imap_emails_job.rb index 23bc1c868..ec5717f3b 100644 --- a/app/jobs/inboxes/fetch_imap_emails_job.rb +++ b/app/jobs/inboxes/fetch_imap_emails_job.rb @@ -13,7 +13,8 @@ class Inboxes::FetchImapEmailsJob < MutexApplicationJob end rescue *ExceptionList::IMAP_EXCEPTIONS => e Rails.logger.error "Authorization error for email channel - #{channel.inbox.id} : #{e.message}" - rescue EOFError, OpenSSL::SSL::SSLError, Net::IMAP::NoResponseError, Net::IMAP::BadResponseError, Net::IMAP::InvalidResponseError => e + rescue EOFError, OpenSSL::SSL::SSLError, Net::IMAP::NoResponseError, Net::IMAP::BadResponseError, Net::IMAP::InvalidResponseError, + Net::IMAP::ResponseParseError, Net::IMAP::ResponseReadError, Net::IMAP::ResponseTooLargeError => e Rails.logger.error "Error for email channel - #{channel.inbox.id} : #{e.message}" rescue LockAcquisitionError Rails.logger.error "Lock failed for #{channel.inbox.id}"