apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tim Bray <Tim.B...@Sun.COM>
Subject apr_file_* weirdness on Mac OS X
Date Fri, 03 Oct 2008 06:40:28 GMT
I'm developing a module which accepts a large number of POST requests,  
receives the request bodies, and persists them into ordinary files in  
the filesystem.  On OS X, there are occasions where the file is  
(rarely) transiently not there.  The idiom looks like this

     status = apr_file_open(&fp, tempname, APR_FOPEN_WRITE |  
                            PERMS, pool);

     /* ... do lots of writing ... */


     status = apr_file_rename(tempname, filename, pool); /* filename  
is in the same directory as tempname */
     BOOM! strerror() says "no such file or directory"

Then if I go and look, what do you know, the tempfile actually is  
there.  If I process 500 requests in a big hurry, 100 each from 5  
concurrent clients, this will happen maybe half a dozen times, in an  
unpredictable order.  There are ways to work around this, but still,  
it's kinda disturbing.  It's either, in decreasing order of  
probability (a) me doing something stupid, (b) OS X filesystem  
weirdness, (c) an APR bug.  apr_file_write_full() doesn't seem to make  
a difference.

Same code running in -X single-threaded mode, no problem.  Same code  
on Solaris, no problem.  (Well, yes, there are other weird Solaris  
problems with mutexes, but we'll get to those).


View raw message