How to fix imap-dovecot consecutive fails

Last days i was receiving a notice at my email from cpanel’s monitor service that imap was failing. The exact message was :

imap failed @ 'time'. A restart was attempted automagically.
Service Check Method: [check command]
Number of Restart Attempts: 1
Cmd Service Check Raw Output: dovecot is not running

I was getting this message once a day, everyday, same time. I started digging at the logs and found out that at the time i had the failure there was a script running. The script was upcp and this was for updating cpanel.

I also found the entry below at /var/log/maillog

dovecot: dovecot: Fatal: Time just moved backwards by 6 seconds. This might cause a lot of problems, so I'll just kill myself now. http://wiki.dovecot.org/TimeMovedBackwards

So the problem was with the clock skewing backwards and since dovecot is time sensitive it had troubles running smoothly.

From dovecot’s wiki :

Dovecot v2.0 finally tries to handle this a bit more gracefully. Its behavior when time moves backwards is:

Existing imap and pop3 processes either sleep or die, just like with older versions
Master process stops creating new processes until either the original time is reached, or after a maximum wait of 3 minutes.
Other processes log a warning, but do nothing else.
Timeouts are updated so that the timeout is executed approximately at the original intended time.
Dovecot v2.0 also notices when time unexpectedly jumps forwards. In that situation it logs a warning and also updates timeouts.

The reason why imap/pop3 processes get killed and new ones can't be created for a while is to avoid problems related to timestamps. Some issues are:

Uniqueness of Maildir filenames and dbox global unique identifiers relies on a growing timestamp
Dotlock files' staleness is detected by looking at its mtime.
Timestamps are stored internally all around in memory (as well as in index files) and compared to current time. Those checks may or may not be buggy if current time shrinks.

The solution i tried and for now it seems that it’s working is to install and enable the ntp protocol so as to syncronize the time and not have that much clock skew.

Just for the record :
yum install ntp
chkconfig ntpd on
ntpdate pool.ntp.org
/etc/init.d/ntpd start

Sources i used : 1

This entry was posted in cpanel, How to, Linux and tagged , , , , . Bookmark the permalink.
  • http://lpic.lt LPIC.lt

    I have alittle different situation, i have managed it… somehow…

    i have dovecot listening IMAP (not imaps, just simple imap) on 143 and 31337.

    and somehow imap 143 stopped responding… i have removed listening 31337 port, and one IMAP port is working now… but it is interesting… i do not understand why… maybe somebody has some ideas?

    by the way… i had ntpdate working 3 min and 0,5,15 hours now i made it every hour… :) but it wasn’t the key in problem solving… and listening crashed not at that time… and at the moment it’s first time, hope, it will be the last :)

  • tcb13

    Thank you! Saved my day.