From:             
Operating system: Irrelevant
PHP version:      5.3.3
Package:          Scripting Engine problem
Bug Type:         Bug
Bug description:file_put_contents doesn't release the LOCK_EX

Description:
------------
The name is pretty self explanatory. When the file_put_content function is
used along with the LOCK_EX flag, the file descriptor / file handle doesn't
get unlocked. Most of the time this won't be an issue, but depending on the
underlying file system, it could lead to severe application crash. Such
example is the GlusterFS version packaged for the Ubuntu 10.04 which would
block the PHP process in uninterruptible sleep. I know that most of the
time this situation won't affect real life scenarios, but it already took
down a virtual host from our production cluster, based onto the above
setup.

Test script:
---------------
<?php

file_put_contents('foo', 'bar', LOCK_EX);

$fh = fopen($file, 'rb');

flock($fh, LOCK_SH);

$file_contents = stream_get_contents($fh);

flock($fh, LOCK_UN);

fclose($fh);

echo $file_contents.PHP_EOL;

Expected result:
----------------
output: bar

strace:

getcwd("/media/glusterfs01/gluster-bug", 4096) = 31

lstat("/media/glusterfs01/gluster-bug/foo", {st_mode=S_IFREG|0644,
st_size=3, ...}) = 0

open("/media/glusterfs01/gluster-bug/foo", O_WRONLY|O_CREAT, 0666) = 3

fstat(3, {st_mode=S_IFREG|0644, st_size=3, ...}) = 0

lseek(3, 0, SEEK_CUR)                   = 0

flock(3, LOCK_EX)                       = 0

ftruncate(3, 0)                         = 0

write(3, "bar", 3)                      = 3

flock(3, LOCK_UN)                       = 0

close(3)                                = 0

getcwd("/media/glusterfs01/gluster-bug", 4096) = 31

open("/media/glusterfs01/gluster-bug/foo", O_RDONLY) = 3

fstat(3, {st_mode=S_IFREG|0644, st_size=3, ...}) = 0

lseek(3, 0, SEEK_CUR)                   = 0

flock(3, LOCK_SH)                       = 0

fstat(3, {st_mode=S_IFREG|0644, st_size=3, ...}) = 0

read(3, "bar", 8192)                    = 3

read(3, "", 8192)                       = 0

read(3, "", 8192)                       = 0

flock(3, LOCK_UN)                       = 0

close(3)                                = 0





Actual result:
--------------
output: none

strace:

getcwd("/media/glusterfs01/gluster-bug", 4096) = 31

lstat("/media/glusterfs01/gluster-bug/foo", {st_mode=S_IFREG|0644,
st_size=3, ...}) = 0

open("/media/glusterfs01/gluster-bug/foo", O_WRONLY|O_CREAT, 0666) = 3

fstat(3, {st_mode=S_IFREG|0644, st_size=3, ...}) = 0

lseek(3, 0, SEEK_CUR)                   = 0

flock(3, LOCK_EX)                       = 0

ftruncate(3, 0)                         = 0

write(3, "bar", 3)                      = 3

flock(3, LOCK_UN)                       = 0

close(3)                                = 0

getcwd("/media/glusterfs01/gluster-bug", 4096) = 31

open("/media/glusterfs01/gluster-bug/foo", O_RDONLY) = 3

fstat(3, {st_mode=S_IFREG|0644, st_size=3, ...}) = 0

lseek(3, 0, SEEK_CUR)                   = 0

flock(3, LOCK_SH



And then it blocks here ...



-- 
Edit bug report at http://bugs.php.net/bug.php?id=53076&edit=1
-- 
Try a snapshot (PHP 5.2):            
http://bugs.php.net/fix.php?id=53076&r=trysnapshot52
Try a snapshot (PHP 5.3):            
http://bugs.php.net/fix.php?id=53076&r=trysnapshot53
Try a snapshot (trunk):              
http://bugs.php.net/fix.php?id=53076&r=trysnapshottrunk
Fixed in SVN:                        
http://bugs.php.net/fix.php?id=53076&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=53076&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=53076&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=53076&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=53076&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=53076&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=53076&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=53076&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=53076&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=53076&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=53076&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=53076&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=53076&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=53076&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=53076&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=53076&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=53076&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=53076&r=mysqlcfg

Reply via email to