apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stefan Ruppert ...@myarm.com>
Subject Re: Deadlock with apr_file_open(APR_FOPEN_APPEND) and apr_file_lock() under Windows
Date Mon, 11 Oct 2010 06:41:08 GMT
Brian Havard wrote:
> On 08/10/10 23:21, Stefan Ruppert wrote:
>> I have filed a bug in bugzilla for this issue:
>>
>> https://issues.apache.org/bugzilla/show_bug.cgi?id=50058
>>
>> and added a patch which simple removes the calls to apr_file_lock()
>> and apr_file_unlock()!
>>
>> Please can some test this!?
> 
> As I remember it, the file lock is used to ensure proper appending
> behaviour. This is necessary because windows doesn't natively have an
> append mode so it's necessary to seek to the end of the file then write.
> The file lock is used to prevent a race condition when multiple
> threads/processes are writing to the same file simultaneously.
> 
> The deadlock problem needs to be solved by suppressing locking for
> append if a lock is already held, not by simply removing the locking
> completely.

I don't agree. IMHO, a framework (like APR) shouldn't be too clever. The 
application has to decide if it uses a file which can be accessed from 
different threads or processes and needs locking. Regarding threading 
see the ML-thread "apr_file_*() threading issues under Windows" for 
using apr_file_*() API through threads.

Regarding locking a file, I would like to see that the calls to 
apr_file_lock()/apr_file_unlock() are removed from the apr_file_write() 
call. From my usage scenario I need to lock the file over several calls 
to apr_file_write() and why add more complexity if the application needs 
locking by itself!? Also currently with such locking the semantic of the 
apr_file_write() differs between Windows and Unix like OSs.

Also I would like to see a APR_FOPEN_LOCK which locks the file within 
apr_file_open() call and unlocks the file within apr_file_close() call.

> 
> 
>> Stefan Ruppert wrote:
>>> Hi all,
>>>
>>> yesterday I ran into the following problem. I use the apr_file_lock()
>>> function in conjunction with the APR_FOPEN_APPEND flag and under
>>> Linux everything is fine.
>>>
>>> Under Windows any attempt to write to the opened and locked file I
>>> get a deadlock. This is due the fact that apr_file_write() creates an
>>> own lock with apr_file_lock() if the file was opened with the
>>> APR_FOPEN_APPEND flag.
>>>
>>> First this is inconsistent through different operating systems Unix
>>> does not lock, Windows does lock the file in append mode. However, I
>>> think the locking in the Windows implementation is wrong. The user
>>> has to choose if he wants to lock the file or not!
>>>
>>> To reproduce the behavior please compile and test the attached example!
>>>
>>> Any comments? Should I file a bug report?
>>>
>>> Regards,
>>> Stefan
>>>
> 

Mime
View raw message