php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73606 accel_find_interned_string not have read lock
Submitted: 2016-11-25 11:09 UTC Modified: 2021-08-01 04:22 UTC
Votes:1
Avg. Score:1.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: 804368954 at qq dot com Assigned:
Status: No Feedback Package: opcache
PHP Version: 7.0Git-2016-11-25 (Git) OS: CentOS Linux release 6.2 (Final)
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2016-11-25 11:09 UTC] 804368954 at qq dot com
Description:
------------
when exec "opcache_reset()" by cacheTool, We offen get Fatal error:[25-Nov-2016 14:07:07 Asia/Shanghai] PHP Fatal error:  Unknown: Failed opening required '/home/xxxx/index.php' (include_path='.:/home/php7/lib/php') in Unknown on line 0(just on error log,not warning), then I check ZendAccelerator.c, find this code:
 static zend_string *accel_find_interned_string(zend_string *str)
{
/* for now interned strings are supported only for non-ZTS build */
	zend_ulong h;
	uint nIndex;
	uint idx;
	Bucket *arData, *p;

	if (IS_ACCEL_INTERNED(str)) {
		/* this is already an interned string */
		return str;
	}
	if (!ZCG(counted)) {
		if (accel_activate_add() == FAILURE) {
			return str;
		}
		ZCG(counted) = 1;
	}

	h = zend_string_hash_val(str);
	nIndex = h | ZCSG(interned_strings).nTableMask;

	/* check for existing interned string */
	idx = HT_HASH(&ZCSG(interned_strings), nIndex);
	arData = ZCSG(interned_strings).arData;
	while (idx != HT_INVALID_IDX) {
		p = HT_HASH_TO_BUCKET_EX(arData, idx);
		if ((p->h == h) && (ZSTR_LEN(p->key) == ZSTR_LEN(str))) {
			if (!memcmp(ZSTR_VAL(p->key), ZSTR_VAL(str), ZSTR_LEN(str))) {
				return p->key;
			}
		}
		idx = Z_NEXT(p->val);
	}

	return NULL;
}

it read shared memory, but I don't find read lock in function, because "opcache_rerest()" will execute "accel_interned_strings_restore_state()" function, it will write shared memory. I'm not an expert, so need your help,thanks!


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-07-23 08:04 UTC] nikic@php.net
-Status: Open +Status: Feedback
 [2021-07-23 08:04 UTC] nikic@php.net
Does this problem still manifest on a supported version of PHP?

Generally, reads from opcache SHM always happen without a separate lock. We only track how many SHM users there are. When opcache_reset() is called, the cache is not immediately reset, but only a restart is scheduled. The actual cache reset will only happen once all current SHM users have detached from the cache. At that point nobody should be reading the cache, and it's safe to reset it. For that reason no fine-grained read locking is necessary.
 [2021-08-01 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 05:01:29 2024 UTC