From 7d13817a6ae45058f8e4b91e95d4c62b22c160be Mon Sep 17 00:00:00 2001 From: Marek Blaha Date: Mon, 7 Oct 2024 15:20:05 +0200 Subject: [PATCH] Catch more specific OSError instead of SMTPException in dnf-automatic email emitter Resolves: RHEL-49743 --- ...plib-catch-OSError-not-SMTPException.patch | 33 +++++++++++++++++++ dnf.spec | 7 +++- 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 0031-smtplib-catch-OSError-not-SMTPException.patch diff --git a/0031-smtplib-catch-OSError-not-SMTPException.patch b/0031-smtplib-catch-OSError-not-SMTPException.patch new file mode 100644 index 0000000..28a5409 --- /dev/null +++ b/0031-smtplib-catch-OSError-not-SMTPException.patch @@ -0,0 +1,33 @@ +From ea2d17cc484c7c49686145f4b2e98e4b73b9c967 Mon Sep 17 00:00:00 2001 +From: Evan Goode +Date: Mon, 13 Mar 2023 14:50:41 -0400 +Subject: [PATCH] smtplib: catch OSError, not SMTPException + +Some, but not all, types of connection error are caught by smtplib and +reraised as an smtplib.SMTPException. Notably, TimeoutError, +socket.gaierror (name resolution failure), and ConnectionRefusedError +and are not caught. + +The more generic OSError should be caught here instead. + +Resolves #1905 +--- + dnf/automatic/emitter.py | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/dnf/automatic/emitter.py b/dnf/automatic/emitter.py +index 4aea4b02..648f1a1d 100644 +--- a/dnf/automatic/emitter.py ++++ b/dnf/automatic/emitter.py +@@ -106,7 +106,7 @@ class EmailEmitter(Emitter): + smtp = smtplib.SMTP(self._conf.email_host, timeout=300) + smtp.sendmail(email_from, email_to, message.as_string()) + smtp.close() +- except smtplib.SMTPException as exc: ++ except OSError as exc: + msg = _("Failed to send an email via '%s': %s") % ( + self._conf.email_host, exc) + logger.error(msg) +-- +2.46.1 + diff --git a/dnf.spec b/dnf.spec index 1c47a88..d83a512 100644 --- a/dnf.spec +++ b/dnf.spec @@ -69,7 +69,7 @@ It supports RPMs, modules and comps groups & environments. Name: dnf Version: 4.14.0 -Release: 18%{?dist} +Release: 19%{?dist} Summary: %{pkg_summary} # For a breakdown of the licensing, see PACKAGE-LICENSING License: GPLv2+ @@ -105,6 +105,7 @@ Patch27: 0027-Add-detection-for-ostree-based-systems-and-warn-user.patch Patch28: 0028-Update-ostree-bootc-host-system-check.patch Patch29: 0029-Update-bootc-hosts-message-to-point-to-bootc-help.patch Patch30: 0030-Allow-installroot-on-read-only-bootc-system.patch +Patch31: 0031-smtplib-catch-OSError-not-SMTPException.patch BuildArch: noarch @@ -394,6 +395,10 @@ popd %{python3_sitelib}/%{name}/automatic/ %changelog +* Mon Oct 07 2024 Marek Blaha - 4.14.0-19 +- Catch more specific OSError instead of SMTPException in dnf-automatic email + emitter (RHEL-49743) + * Tue Oct 01 2024 Petr Pisar - 4.14.0-18 - More specific error message on a locked OSTree system or a bootc system without a usr-overlay (RHEL-49670)