]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Avoid logging the same mail istream read error multiple times
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Wed, 21 Apr 2021 16:18:07 +0000 (19:18 +0300)
committerTimo Sirainen <timo.sirainen@open-xchange.com>
Mon, 26 Apr 2021 12:50:20 +0000 (15:50 +0300)
src/lib-storage/index/index-mail.c
src/lib-storage/index/index-mail.h

index 8804006c5cc90f66f46249b479a340d6c9bf86e8..01237ec236adbac0f4ea8d486070158a900a73e2 100644 (file)
@@ -1259,9 +1259,23 @@ void index_mail_stream_log_failure_for(struct index_mail *mail,
                if (_mail->expunged)
                        return;
        }
-       mail_set_critical(_mail,
-               "read(%s) failed: %s (read reason=%s)",
-               i_stream_get_name(input), i_stream_get_error(input),
+
+       const char *old_error =
+               mailbox_get_last_internal_error(_mail->box, NULL);
+       const char *new_error = t_strdup_printf("read(%s) failed: %s",
+               i_stream_get_name(input), i_stream_get_error(input));
+
+       if (mail->data.istream_error_logged &&
+           strstr(old_error, new_error) != NULL) {
+               /* Avoid logging the same istream error multiple times
+                  (even if the read reason is different). The old_error begins
+                  with the UID=n prefix, which we can ignore since we know
+                  that this mail already logged a critical error, so it has
+                  to be about this same mail. */
+               return;
+       }
+       mail->data.istream_error_logged = TRUE;
+       mail_set_critical(_mail, "%s (read reason=%s)", new_error,
                mail->mail.get_stream_reason == NULL ? "" :
                mail->mail.get_stream_reason);
 }
index 88480ee35cd5edd7d90723bf45640899e8a996bf..57f213ff0e1e271dec8ebe7027118412a6d24f7a 100644 (file)
@@ -125,6 +125,7 @@ struct index_mail_data {
        bool header_parsed:1;
        bool no_caching:1;
        bool forced_no_caching:1;
+       bool istream_error_logged:1;
        bool destroying_stream:1;
        bool initialized_wrapper_stream:1;
        bool destroy_callback_set:1;