BUG? File descriptor use in cmd_append (for MULTIAPPEND) results in many open files

Nik Conwell nik at bu.edu
Mon Dec 11 13:55:29 EST 2006

On Dec 11, 2006, at 1:02 PM, Rich Graves wrote:

> Nik Conwell wrote:
>> multiple messages being appended).  Cyrus-imapd handles this  
>> multiappend by creating stage files for each appended message and  
>> leaving the file descriptor open.  The problem is that after 240  
>> messages, we run out of file descriptors and so an open() of the  
>> next stage file fails with EMFILE.  I updated /etc/cyrus.conf to  
>> make the max fds be 1024 (AFAICT kernel MAX) which helped somewhat  
>> but not for larger mailboxes with > 1008 messages.
> Excellent troubleshooting. I'm getting worried that I have a  
> problem and don't know it. Did you get useful error messages (that  
> we can search for, too)?

The server logs:
   IOERROR: creating message file /var/spool/imap/stage./ 
828-1165849099-1008: File exists

The file is named pid-timestamp-stage_sequence_number

The "File exists" error is bogus.  With strace you see the real error:

open("/var/spool/imap/stage./828-1165849099-1008", O_RDWR|O_CREAT| 
O_TRUNC, 0666) = -1 EMFILE (Too many open files)

and then the code goes on try a mkdir so it loses the errno:

mkdir("/var/spool/imap/stage./", 0755)  = -1 EEXIST (File exists)

following through the rest of the trace you see everything being  

close(1023)                             = 0
munmap(0xb652b000, 4096)                = 0
unlink("/var/spool/imap/stage./828-1165849099-1007") = 0
close(1022)                             = 0
munmap(0xb652c000, 4096)                = 0
unlink("/var/spool/imap/stage./828-1165849099-1006") = 0
close(1021)                             = 0


> The man page for cyrus.conf suggests that the default is 256, but  
> that the integer value is optional. So if maxfds does not appear in  
> cyrus.conf at all, is the default 256, or is it unlimited (up to  
> ulimit)? Looks like the former to me. Ick.

Looks like the former to me as well since it was crapping out at 240  
stage files (a bunch of files already open when it started).

More information about the Info-cyrus mailing list