-
Notifications
You must be signed in to change notification settings - Fork 7.8k
BUG: locks not working as expected #14592
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This isn't quite true. It seems the bug can't be reproduced using the CLI, or using the built-in test server, but one other user said they could reproduce it under FPM-FCGI. Also worth noting is that this is presumably the same bug reported a few years ago on the old tracker, although that too was missing information about the setup used (and had some rather confusing examples): https://bugs.php.net/bug.php?id=54453 Stack overflow discussion in question is here https://stackoverflow.com/q/78633762/157957 with a previous question here https://stackoverflow.com/q/5524073/157957 |
Indeed, using command line on Centos and on Windows the Do you have any suggestion that I can try to make it work with Apache? Also, isnt this a bug that you can fix? I mean, PHP team provides source code to work with Apache, so I think it's up to PHP devs to receive this type of bug complain, right? |
I personally can't fix this, but I wasn't trying to make any comment about whether it could or should be fixed. Rather, I was trying to narrow down the problem, because it's not true that just running that code on any copy of PHP will reproduce the bug, and that's really useful information so that someone knows where to start when trying to fix it. I've just tried on a server I have to hand, and the lock worked correctly, so it would be useful if you could provide more information on the systems you've tested - the exact PHP version, and the server setup. Here's a template with some info I think might be relevant (mostly available in the output of
|
Could it have something to do with the event MPM configuration + Apache handler shared module? If two running PHP scripts are sharing the same PID it would reasonable that the flock passes, as that process is already holding a lock on that file. |
Yeah, that's why I included the "Thread Safety" in my table above. I've never used PHP under Windows, but I understand multi-threading is normal there, and it would explain why it doesn't reproduce under CLI (which is separate processes, obviously.) |
Hi my friends, After reading your comments I tried to simulate the bug again in a complete fresh CentOS 8, CentOS 9 Stream and Windows 11 running Apache/2.4.57 (CentOS Stream) prefork and PHP 8.2.20. The bug happened on all 3 systems. Here is the
I can reliably reproduce this bug on a completely fresh Centos 8, 9 stream and Windws 11. I dont know how to use Ubuntu (as some of you posted above saying the bug does not happen on Ubuntu) but for sure on these 3 operating systems the bug happens reliably. |
@batata004 That's interesting. Could you also post the output from a call to Hopefully someone can spot what the different setups that do and don't show the problem have in common. |
@IMSoP I executed the command you requested. Here is the output on Centos 9 Stream.
On my Windows 11 the output is below:
|
I reproduced in the following environment: PHP Version 8.2.18
|
This bug seems to affect FrankenPHP users too since PHP 8.3.8. PHP 8.2.20 also seems affected. PHP 8.3.7 isn't affected. As Apache MPM prefork, FrankenPHP requires a ZTS build. The problem seems to mainly happen when using Docker for Mac and VirtioFS. WSL+Docker users are also affected. Reports: dunglas/symfony-docker#641, dunglas/frankenphp#886, api-platform/demo#416. Maybe related (I'm not sure at all about this one): docker/for-mac#7004 |
Couldn't reproduce with Apache ZTS nor NTS on my system. |
@nielsdos how I do that please? |
If you're using the CLI SAPI, you can use If you're using php-fpm, I'd recommend running fpm in foreground using the -F option, and strace using -f to track children, e.g. |
It won't stop, so I canceled it |
Thanks. Looking at the syscall trace it seems that it's simply the flock system call that hangs when acquiring a shared lock. Given that it is the system call that causes the hang I don't think we can do anything here as the bug does not seem to be in PHP. Given the fact there's bug reports for Docker on mac about flock I'm thinking the bug is either in Docker or macOS. |
Well, the Windows implementation appears to be broken by design (since it claims to be "bug for bug compatible with Unix"): php-src/ext/standard/flock_compat.c Lines 115 to 133 in 9185f61
If the asynchronous (aka. overlapped) And if the statement "bug for bug compatible with Unix" still holds (it had been written in 1997), Unix systems would behave the same. |
It is kinda strange. We just updated from PHP 8.4.3 to 8.4.4 (Symfony / Frankenphp / ZTS / Debian Bookworm / MacOS 15.2 / Docker For Mac 4.38.0) and this issue just appeared. I couldn't find any related flock changes regarding those versions php-8.4.3...php-8.4.4. I would guess something changed in the underlying c library or with the build tools. Switching back to PHP 8.4.3 and everything works fine. |
Description
The following code:
Save the simple code above to the file
test.php
, for example. Now, in less than 10 seconds apart, open 2 (or more) tabs on your browser calling the filetest.php
and you will see every tab will show youYes
after some seconds. It should showYes
only on the first tab, all the other should return immediatly withNo
because I am using LOCK_NB flag.This bug is pretty simple to reproduce and other people also confirmed it on Stackoverflow when I reported there.
PHP Version
8.x
Operating System
Confirmed at least on centos 9 stream and windows 11
The text was updated successfully, but these errors were encountered: