Bug 51254 - apr_dir_make_recursive can return "file exists"
Summary: apr_dir_make_recursive can return "file exists"
Status: CLOSED FIXED
Alias: None
Product: APR
Classification: Unclassified
Component: APR (show other bugs)
Version: HEAD
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: Apache Portable Runtime bugs mailinglist
URL:
Keywords: FixedInTrunk, PatchAvailable
Depends on:
Blocks:
 
Reported: 2011-05-24 08:49 UTC by William Lee
Modified: 2014-01-21 13:02 UTC (History)
0 users



Attachments
Proposed patch (1.31 KB, patch)
2011-05-24 08:49 UTC, William Lee
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description William Lee 2011-05-24 08:49:22 UTC
Created attachment 27050 [details]
Proposed patch

If there are two calls to apr_dir_make_recursive happening on the same non-existent path, at the same time, it can be that both instances call the apr_dir_make function.  e.g.

thread 1 calls apr_dir_make_recursive on parent
thread 2 calls apr_dir_make_recursive on parent
thread 1 calls apr_dir_make (returns APR_SUCCESS)
thread 2 calls apr_dir_make (returns EEXIST)

In this case the second thread is returned EEXIST despite the documented behaviour for the function being "No error will be reported if PATH already exists".

This is a timing issue and so is relatively rare but has been observed within our product during testing.  The problem can affect both simultaneous threads or simultaneous processes and due to the nature of the code could happen on any platform.

A proposed patch is attached.
Comment 1 Wim Lewis 2011-08-18 17:23:54 UTC
The patch looks good to me. Another approach would be to move the ENOENT test before the existing EEXIST case so that the EEXIST test does double duty.
Comment 2 Stefan Fritsch 2011-10-15 21:28:03 UTC
r1183688, r1183713, r1183715, will be in 1.4.6
Comment 3 Jeff Trawick 2014-01-16 15:24:32 UTC
This was in 1.4.6 and later.

Incidentally, a patch for a related problem was just posted to dev@apr:

http://mail-archives.apache.org/mod_mbox/apr-dev/201401.mbox/%3C012801cf12c6%2403384e40%2409a8eac0%24%40qqmail.nl%3E