Dovecot error: mail stop working and need to restart service

:uk:/:us: Message template (english)

My YunoHost server

Hardware: VPS bought online
YunoHost version: 4.3.6.3
I have access to my server : Through SSH
Are you in a special context or did you perform some particular tweaking on your YunoHost instance ? : no

# lsb_release -a
No LSB modules are available.
Distributor ID:	Debian
Description:	Debian GNU/Linux 10 (buster)
Release:	10
Codename:	buster

Description of my issue

I have noticed the mail is not reaching the Thunderbird client, no new mails appear.
After that, chececk on server but it is working.
It will stop sending and receiving.

Three days ago i did reboot the server, it did solve the problem eventually but the problem came back.

Yesterday I did reload dovecot service and the mail service cambe back eventually.

yunohost service reload doveco

Today did check the syslog tail -100f /var/log/syslog

and came to this possible error

dovecot: auth: Error: net_connect_unix(/var/run/dovecot/stats-writer) failed: Permission denied

checked online and found out this answers about dovecot error:

but they seem to not apply to my case, this is my server:

# ls -l /var/run/dovecot/*stat*
srw------- 1 root  root 0 May  4 13:15 /var/run/dovecot/old-stats
prw------- 1 root  root 0 May  4 13:15 /var/run/dovecot/old-stats-mail
prw------- 1 root  root 0 May  4 13:15 /var/run/dovecot/old-stats-user
srw-rw---- 1 vmail mail 0 May  4 13:15 /var/run/dovecot/stats-reader
srw-rw---- 1 vmail mail 0 May  4 13:15 /var/run/dovecot/stats-writer

and dovecot config:

# cat /etc/dovecot/dovecot.conf 
!include yunohost.d/pre-ext.conf

listen = *, ::
auth_mechanisms = plain login

mail_gid = 8
mail_home = /var/mail/%n
mail_location = maildir:/var/mail/%n
mail_uid = 500

protocols = imap sieve 

mail_plugins = $mail_plugins quota

###############################################################################

# generated 2020-08-18, Mozilla Guideline v5.6, Dovecot 2.3.4, OpenSSL 1.1.1d, intermediate configuration
# https://ssl-config.mozilla.org/#server=dovecot&version=2.3.4&config=intermediate&openssl=1.1.1d&guideline=5.6

ssl = required

ssl_cert = </etc/yunohost/certs/xxxxxxxx.net/crt.pem
ssl_key = </etc/yunohost/certs/xxxxxxxx.net/key.pem

# curl https://ssl-config.mozilla.org/ffdhe2048.txt > /path/to/dhparam
ssl_dh = </usr/share/yunohost/other/ffdhe2048.pem

# intermediate configuration
ssl_min_protocol = TLSv1.2
ssl_cipher_list = ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384
ssl_prefer_server_ciphers = no

###############################################################################


passdb {
  args = /etc/dovecot/dovecot-ldap.conf
  driver = ldap
}

userdb {
  args = /etc/dovecot/dovecot-ldap.conf
  driver = ldap
}

protocol imap {
  imap_client_workarounds =
  mail_plugins = $mail_plugins imap_quota antispam
}


protocol lda {
  auth_socket_path = /var/run/dovecot/auth-master
  mail_plugins = quota sieve
  postmaster_address = postmaster@xxxxxxx.net
}

protocol sieve {
}

service auth {
  unix_listener /var/spool/postfix/private/auth {
    group = postfix
    mode = 0660
    user = postfix
  }
  unix_listener auth-master {
    group = mail
    mode = 0660
    user = vmail
  }
}

service quota-warning {
  executable = script /usr/bin/quota-warning.sh
  user = vmail
  unix_listener quota-warning {
  }
}

service stats {
    unix_listener stats-reader {
        user = vmail
        group = mail
        mode = 0660
    }

    unix_listener stats-writer {
        user = vmail
        group = mail
        mode = 0660
    }
}

plugin {
  sieve = /var/mail/sievescript/%n/.dovecot.sieve
  sieve_dir = /var/mail/sievescript/%n/scripts/
  sieve_before = /etc/dovecot/global_script/
}

plugin {
  antispam_debug_target = syslog
  antispam_verbose_debug = 0
  antispam_backend = pipe
  antispam_spam = Junk;SPAM
  antispam_trash = Trash
  antispam_pipe_program = /usr/bin/rspamc
  antispam_pipe_program_args = -h;localhost:11334;-P;q1
  antispam_pipe_program_spam_arg = learn_spam
  antispam_pipe_program_notspam_arg = learn_ham
}

plugin {
  quota = maildir:User quota
  quota_rule2 = SPAM:ignore
  quota_rule3 = Trash:ignore
}

plugin {
  quota_warning = storage=95%% quota-warning 95 %u
  quota_warning2 = storage=80%% quota-warning 80 %u
  quota_warning3 = -storage=100%% quota-warning below %u # user is no longer over quota
}

also checked the mail logs

# cat /var/log/mail.err
May  1 12:29:54 xxxxxxx dovecot: imap(yyyyy)<12113><3Ozfv/DdhJVdsLGm>: Error: stat(/var/mail/yyyyy/.dovecot.sieve/tmp) failed: Not a directory
May  1 13:42:29 xxxxxxx dovecot: imap(yyyyy)<12831><BP3Aw/HdcpddsLGm>: Error: stat(/var/mail/yyyyy/.dovecot.sieve/tmp) failed: Not a directory
May  1 15:12:23 xxxxxxx dovecot: imap(yyyyy)<13553><oW5TBfPdjphdsLGm>: Error: stat(/var/mail/yyyyy/.dovecot.sieve/tmp) failed: Not a directory
May  1 19:55:22 xxxxxxx dovecot: imap(yyyyy)<2001><LR8t+fbdIqJdsLGm>: Error: stat(/var/mail/yyyyy/.dovecot.sieve/tmp) failed: Not a directory
May  1 20:35:46 xxxxxxx dovecot: imap(yyyyy)<2272><g0DDiffdwqJdsLGm>: Error: stat(/var/mail/yyyyy/.dovecot.sieve/tmp) failed: Not a directory
May  1 21:29:57 xxxxxxx dovecot: imap(yyyyy)<2660><EYSNS/jd/qJdsLGm>: Error: stat(/var/mail/yyyyy/.dovecot.sieve/tmp) failed: Not a directory
May  1 22:01:19 xxxxxxx dovecot: imap(yyyyy)<2869><PNP1u/jdUKNdsLGm>: Error: stat(/var/mail/yyyyy/.dovecot.sieve/tmp) failed: Not a directory
May  2 09:06:47 xxxxxxx dovecot: imap(yyyyy)<9659><KLW2BwLeuLNdsLGm>: Error: stat(/var/mail/yyyyy/.dovecot.sieve/tmp) failed: Not a directory
May  2 15:58:10 xxxxxxx dovecot: lda(yyyyy@xxxxxxx.net)<15294><TyU+FHLjb2K+OwAAu7SGQA>: Error: sieve: msgid=<luz6ukq1qj@localhost.localdomain>: failed to store into mailbox 'Junk': Mailbox doesn't exist: Junk
May  2 15:58:10 xxxxxxx dovecot: lda(yyyyy@xxxxxxx.net)<15294><TyU+FHLjb2K+OwAAu7SGQA>: Error: sieve: Execution of script /etc/dovecot/global_script/rspamd.sieve failed, but implicit keep was successful
May  3 11:48:50 xxxxxxx dovecot: imap(yyyyy)<15748><48WdaBjeALBdsLGm>: Error: stat(/var/mail/yyyyy/.dovecot.sieve/tmp) failed: Not a directory
May  3 12:25:28 xxxxxxx dovecot: imap(yyyyy)<16019><t0Fu6RjeRLFdsLGm>: Error: stat(/var/mail/yyyyy/.dovecot.sieve/tmp) failed: Not a directory
May  3 16:48:43 xxxxxxx dovecot: lda(yyyyy@xxxxxxx.net)<30590><43bSE8tAcWJ+dwAAu7SGQA>: Error: sieve: msgid=<CAB15NYN60BDrHR0tDkXgSaP8E6-Ofm2W88Y+2aqn8oBUi9E8kQ@mail.gmail.com>: failed to store into mailbox 'Junk': Mailbox doesn't exist: Junk
May  3 16:48:43 xxxxxxx dovecot: lda(yyyyy@xxxxxxx.net)<30590><43bSE8tAcWJ+dwAAu7SGQA>: Error: sieve: Execution of script /etc/dovecot/global_script/rspamd.sieve failed, but implicit keep was successful
May  3 20:22:14 xxxxxxx dovecot: lda(yyyyy@xxxxxxx.net)<1590><aF5DLdZycWI2BgAAu7SGQA>: Error: sieve: msgid=<0.0.0.4F.1D85F1873F6FD32.450C70@mail.godashz.xyz>: failed to store into mailbox 'Junk': Mailbox doesn't exist: Junk
May  3 20:22:14 xxxxxxx dovecot: lda(yyyyy@xxxxxxx.net)<1590><aF5DLdZycWI2BgAAu7SGQA>: Error: sieve: Execution of script /etc/dovecot/global_script/rspamd.sieve failed, but implicit keep was successful
May  3 23:49:48 xxxxxxx dovecot: imap(yyyyy)<3637><ZokLfCLesqddsLGm>: Error: stat(/var/mail/yyyyy/.dovecot.sieve/tmp) failed: Not a directory
May  4 10:18:19 xxxxxxx dovecot: lda(yyyyy@xxxxxxx.net)<10661><ZhuRDss2cmKlKQAAu7SGQA>: Error: sieve: msgid=<20220504070606-0.1.3k.1fw9s.0.c7ibm4eb6c@proacount24.com>: failed to store into mailbox 'Junk': Mailbox doesn't exist: Junk
May  4 10:18:19 xxxxxxx dovecot: lda(yyyyy@xxxxxxx.net)<10661><ZhuRDss2cmKlKQAAu7SGQA>: Error: sieve: Execution of script /etc/dovecot/global_script/rspamd.sieve failed, but implicit keep was successful
May  4 12:57:08 xxxxxxx dovecot: lda(yyyyy@xxxxxxx.net)<12596><d4v5BwRccmI0MQAAu7SGQA>: Error: sieve: msgid=<6272864A.3090706@mailcatch.com>: failed to store into mailbox 'Junk': Mailbox doesn't exist: Junk
May  4 12:57:08 xxxxxxx dovecot: lda(yyyyy@xxxxxxx.net)<12596><d4v5BwRccmI0MQAAu7SGQA>: Error: sieve: Execution of script /etc/dovecot/global_script/rspamd.sieve failed, but implicit keep was successful
May  4 12:57:08 xxxxxxx dovecot: lda(zzzzz@xxxxxxx.net)<12598><TwpZCQRccmI2MQAAu7SGQA>: Error: sieve: msgid=<6272864A.3090706@mailcatch.com>: failed to store into mailbox 'Junk': Mailbox doesn't exist: Junk
May  4 12:57:08 xxxxxxx dovecot: lda(zzzzz@xxxxxxx.net)<12598><TwpZCQRccmI2MQAAu7SGQA>: Error: sieve: Execution of script /etc/dovecot/global_script/rspamd.sieve failed, but implicit keep was successful
May  4 13:04:44 xxxxxxx dovecot: auth: Error: net_connect_unix(/var/run/dovecot/stats-writer) failed: Permission denied
May  4 13:11:45 xxxxxxx dovecot: doveadm: Error: This is Dovecot's error log (1651662705)
May  4 13:11:45 xxxxxxx dovecot: doveadm: Fatal: This is Dovecot's fatal log (1651662705)
May  4 13:13:18 xxxxxxx dovecot: doveadm: Error: This is Dovecot's error log (1651662798)
May  4 13:13:18 xxxxxxx dovecot: doveadm: Fatal: This is Dovecot's fatal log (1651662798)
May  4 13:13:24 xxxxxxx dovecot: doveadm: Error: This is Dovecot's error log (1651662804)
May  4 13:13:24 xxxxxxx dovecot: doveadm: Fatal: This is Dovecot's fatal log (1651662804)
May  4 13:15:24 xxxxxxx dovecot: auth: Error: net_connect_unix(/var/run/dovecot/stats-writer) failed: Permission denied
May  4 13:30:25 xxxxxxx dovecot: imap(yyyyy)<1947><R6ow8i3e7rxdsLGm>: Error: stat(/var/mail/yyyyy/.dovecot.sieve/tmp) failed: Not a directory

it seems to be a missconfigured path:

# ls -alF /var/mail/yyyyy/.dovecot.sieve 
lrwxrwxrwx 1 vmail mail 21 Mar  7  2019 /var/mail/yyyyy/.dovecot.sieve -> sieve/roundcube.sieve
# ls -alF /var/mail/yyyyy/sieve/
total 24
drwx------  3 vmail mail  4096 Dec 26  2020 ./
drwx------ 87 vmail mail 12288 May  4 13:30 ../
-rw-------  1 vmail mail   154 Apr 19  2020 roundcube.sieve
drwx------  2 vmail mail  4096 Apr 19  2020 tmp/

I use two mail clients:

  • Thunderbird 1:91.8.1-1
  • K-9 version 6 in Lineage OS 18

Issue is not solved. Though to bypass the situation I applied a hack in cron, by automatically reload service every 30 minutes I will get to fetch and save emails.

# /etc/cron.d/yunohost-reload-dovecot
#
#  Added this cron job to solve issue with dovecot:
#  https://forum.yunohost.org/t/dovecot-error-mail-stop-working-and-need-to-restart-service/19726
#
#  
# Look for and reload service every 30 minutes on minute 6 and 36


SHELL=/bin/bash
6,36 * * * * root : YunoHost reload dovecot service; sleep $((RANDOM\%1200)); yunohost service reload dovecot || echo "Reloading Dovecot to solve issue "