php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #51771 fclose() seems not to unlock the file
Submitted: 2010-05-08 11:48 UTC Modified: 2010-05-14 09:43 UTC
From: kulakov74 at yandex dot ru Assigned: degeberg (profile)
Status: Closed Package: Filesystem function related
PHP Version: 5.3.2 OS: Linux
Private report: No CVE-ID: None
 [2010-05-08 11:48 UTC] kulakov74 at yandex dot ru
Description:
------------
We have a script that runs in a multiprocess way and it uses flock() for interprocess communication. Things worked fine until we moved to PHP 5.3.2 where all the processes started to hang all of a sudden. I debugged the issues and tried several fixes but they didn't solve it. 

I made an extensive log of all the script did in order to find out the reason, and I got a situation with 4 scripts running trying to get a non-blocking lock every second, and all of them wrote "lock failed" to the log. At the same time none of them was supposed to hold the lock at that time. 

Finally I added an flock($hLock, LOCK_UN); before every fclose($hLock); and  it is only that that they stopped handing. 

Test script:
---------------
$H=fopen($LockFile, 'a'); flock($H, LOCK_EX);
//...
//flock($H, LOCK_UN); - the fix
fclose($H);

Expected result:
----------------
no deadlock

Actual result:
--------------
Deadlock

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-05-12 05:41 UTC] crrodriguez at opensuse dot org
Correct, take  look at the changelog..it clearly says:


"Removed automatic file descriptor unlocking happening on shutdown and/or stream 
close (on all OSes). (Tony, Ilia)"

aka. the correct behaviour.
 [2010-05-12 07:20 UTC] kulakov74 at yandex dot ru
-Type: Bug +Type: Documentation Problem
 [2010-05-12 07:20 UTC] kulakov74 at yandex dot ru
Ah thanks then it's only a matter of fixing the documentation for fclock() which still states

The lock is released also by fclose() (which is also called automatically when script finished).

http://www.php.net/manual/en/function.flock.php
 [2010-05-14 09:43 UTC] degeberg@php.net
Automatic comment from SVN on behalf of degeberg
Revision: http://svn.php.net/viewvc/?view=revision&revision=299368
Log: Fixed PHP bug #51771 (fclose() seems not to unlock the file)
 [2010-05-14 09:43 UTC] degeberg@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: degeberg
 [2010-05-14 09:43 UTC] degeberg@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Wed Feb 01 20:04:13 2023 UTC