Skip to content

php still tries to unlock the shared memory ZendSem with opcache.file_cache_only=1 but it was never locked #11336

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

Closed
tifeit opened this issue May 29, 2023 · 0 comments · Fixed by ThePHPF/thephp.foundation#90

Comments

@tifeit
Copy link

tifeit commented May 29, 2023

Description

This is not a big deal, as the error happens in this case on PHP exit, the PHP code works, but maybe there are some other corner cases where this might be an issue.

mkdir /tmp/phpopcache

sudo chmod 777 /tmp/phpopcache

echo "<?php echo 'hi';" > test.php

sudo strace -s 256 -o strace.txt -u www-data /usr/bin/php -dopcache.enable=1 -dopcache.enable_cli=1 -dopcache.file_cache_only=1 -dopcache.file_cache="/tmp/phpopcache" -dopcache.log_verbosity_level=4 -dopcache.error_log=/tmp/opcache.error -f test.php

will produce

cat /tmp/opcache.error
Mon May 29 09:07:24 2023 (25731): Debug UnlockAll:  Bad file descriptor (9)
grep EBADF strace.txt
fcntl(0, F_SETLK, {l_type=F_UNLCK, l_whence=SEEK_SET, l_start=0, l_len=0}) = -1 EBADF (Bad file descriptor)

It seems like the lock file is created here
https://github.com/php/php-src/blob/master/ext/opcache/zend_shared_alloc.c#L103

but this code is executed only when the file_cache_only=0

if (!file_cache_only) {

i.e. the lock file is not created with file_cache_only=1

but regardless of the file_cache_only directive, the code tries to unlock it and generates the error here
https://github.com/php/php-src/blob/master/ext/opcache/ZendAccelerator.c#L401

PHP Version

8.1.17

Operating System

Ubuntu 18.04

nielsdos added a commit to nielsdos/php-src that referenced this issue May 29, 2023
…with opcache.file_cache_only=1 but it was never locked

I chose to check for the value of lock_file instead of checking the
file_cache_only, because it is probably a little bit faster and we're
going to access the lock_file variable anyway. It's also more generic.
nielsdos added a commit that referenced this issue May 30, 2023
* PHP-8.1:
  Fix DOMElement::append() and DOMElement::prepend() hierarchy checks
  Fix spec compliance error for DOMDocument::getElementsByTagNameNS
  Fix GH-11336: php still tries to unlock the shared memory ZendSem with opcache.file_cache_only=1 but it was never locked
  Fix GH-11338: SplFileInfo empty getBasename with more than one slash
nielsdos added a commit that referenced this issue May 30, 2023
* PHP-8.2:
  Fix DOMElement::append() and DOMElement::prepend() hierarchy checks
  Fix spec compliance error for DOMDocument::getElementsByTagNameNS
  Fix GH-11336: php still tries to unlock the shared memory ZendSem with opcache.file_cache_only=1 but it was never locked
  Fix GH-11338: SplFileInfo empty getBasename with more than one slash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment