File locking and IMAP writes

Occasionally in the lab, users have had problems accessing or copying email from their inbox.  The cause is often kernel file locking.  Here are the two situations I’ve seen the problem occur in:

  1. User has a problem with Pine, and it crashes or is killed in a way that doesn’t release the kernel lock on the file (kill -9).
  2. An offline operation to move a message (“UID COPY”) from one IMAP folder to another fails in some way, saying “Timeout while waiting for lock”.

For us, the first case is much more common.  Yesterday was the first time I’ve seen something like #2.  A user was unable to copy a message from his inbox to another imap folder in Apple Mail.  Our server is running dovecot, so I checked and saw that there was a .lock file being created and that the imap process moving the email was frozen.

I did the following:

  • stopped the imap process and closed the client mail app
  • ls -li imapfolder to get the inode number of the file (we use mbox format so all imap folders are files)
  • cat /proc/locks to check and see if there was a kernel lock on the file
  • mv imapfolder imapfolder_tmp; cp imapfolder_tmp imapfolder This creates a new file with a new inode number that can be written.

Tags: ,

Comments are closed.