From: Timo Sirainen Date: Wed, 21 Apr 2021 16:18:07 +0000 (+0300) Subject: lib-storage: Avoid logging the same mail istream read error multiple times X-Git-Tag: 2.3.15~42 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0b24b0c1fcc1163e34e2c40248f784c3b7c87db5;p=thirdparty%2Fdovecot%2Fcore.git lib-storage: Avoid logging the same mail istream read error multiple times --- diff --git a/src/lib-storage/index/index-mail.c b/src/lib-storage/index/index-mail.c index 8804006c5c..01237ec236 100644 --- a/src/lib-storage/index/index-mail.c +++ b/src/lib-storage/index/index-mail.c @@ -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); } diff --git a/src/lib-storage/index/index-mail.h b/src/lib-storage/index/index-mail.h index 88480ee35c..57f213ff0e 100644 --- a/src/lib-storage/index/index-mail.h +++ b/src/lib-storage/index/index-mail.h @@ -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;