#1072: Race conditions in AgaviConfigCache::writeCacheFile() may produce corrupt
files
--------------------+-------------------------------------------------------
Reporter: david | Owner: david
Type: defect | Status: new
Priority: normal | Milestone: 1.0.1
Component: config | Version: 1.0.0
Severity: major | Keywords:
Has_patch: 0 |
--------------------+-------------------------------------------------------
When compiled versions of configuration files are written, many concurrent
processes doing this same thing (due to non-existant or outdated compile)
may result in corrupt compiled files.
The solution would be to compile to a temporary file, and renaming it
afterwards. Using {{{tempnam()}}} seems to be the best way, as it is also
immune to race condition, according to the documentation. The rename
operation is atomic, as it uses system calls, so the race condition is
eliminated.
Special caution needs to be taken for Windows environments; it's not
possible to rename a file to an existing destination on PHP versions
before 5.2.6 (see http://bugs.php.net/bug.php?id=44805). The suggested
approach here is to use {...@rename()}}}, and if that returns false,
{{{copy()}}} the tempfile (which works on Windows, too) and
{{{unlink()}}} it afterwards (inspired by
http://php.net/manual/en/function.rename.php#56576)
Of course, this does not prevent many concurrent processes from all
triggering the same compilation procedure, so there will still be a
significant peak in system load when re-publishing high traffic web sites,
but at least there is no risk of the system being in an unrecoverable
state anymore.
--
Ticket URL: <http://trac.agavi.org/ticket/1072>
Agavi <http://www.agavi.org/>
An MVC Framework for PHP5
_______________________________________________
Agavi Tickets Mailing List
[email protected]
http://lists.agavi.org/mailman/listinfo/tickets