User tests: Successful: Unsuccessful:
Pull Request for Issue #10706.
flock()
if the file does not exist, replace flag r+b
to c+b
in fopen
function.$_fileopen
resource in $this->_locked_files variable.unlock()
do not re-open cache file, but release lock only.Code review.
Or standard test below.
Before patch.
libraries/joomla/cache/storage/file.php
( https://github.com/joomla/joomla-cms/pull/10767/files#diff-056f1b3f5ee42d2b80e891d375789137L309 )usleep(100);
to
usleep(100); JLog::add("Joomla call usleep!!!", JLog::WARNING, 'jerror');
cache
. Clear cache.After patch do the same but
at point 5 you should not see "Joomla call usleep!!!"
Status | New | ⇒ | Pending |
Labels |
Added:
?
|
Category | ⇒ | Cache |
I have added a test instruction in first comment.
Thank you
Title |
|
Title |
|
Title |
|
Category | Cache | ⇒ | Libraries Cache |
Title |
|
Category | Cache Libraries | ⇒ | Unit Tests Cache |
Labels |
Added:
?
|
Feel free to test.
I have tested this item
Category | Cache Unit Tests | ⇒ | Libraries Unit Tests Cache |
Title |
|
Title |
|
I have tested this item
Thanks for tests.
First test was done before 'resolve merge conflict' but 'conflicted' merged PR 13372 only change "
to '
.
Can we add RTC as we have two success tests.
@csthomas We should have another test, please, since we had new commits after the test of @franz-wohlkoenig.
If he can test it again, it would be great
will do
I have tested this item
thanks
I have tested this item
Status | Pending | ⇒ | Ready to Commit |
RTC
Status | Ready to Commit | ⇒ | Fixed in Code Base |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2017-02-04 20:39:00 |
Closed_By | ⇒ | rdeutz | |
Labels |
Added:
?
|
I'm checking it
Thanks :)
I see a few solution.
The reason is that the cache create a lock
before call view method.
If view method generete 404 then process call error page and die.
Cache method does not get any response about failed view.
Cache file is empty and stay to the next requests.
shutdown
function to delete such cache file.diff --git a/libraries/joomla/cache/storage/file.php b/libraries/joomla/cache/storage/file.php
index f2dba86e5f..c4d01e4ed7 100644
--- a/libraries/joomla/cache/storage/file.php
+++ b/libraries/joomla/cache/storage/file.php
@@ -361,6 +361,19 @@ class JCacheStorageFile extends JCacheStorage
{
// Remember resource, flock release lock if you unset/close resource
$this->_locked_files[$path] = $_fileopen;
+
+ $pointer =& $this->_locked_files[$path];
+
+ // Delete file on unexpected die.
+ $deleteMe = function () use ($pointer, $path)
+ {
+ if ($pointer)
+ {
+ unlink($path);
+ }
+ };
+
+ register_shutdown_function($deleteMe);
}
diff --git a/libraries/joomla/cache/storage/file.php b/libraries/joomla/cache/storage/file.php
index f2dba86e5f..ac0f54ccad 100644
--- a/libraries/joomla/cache/storage/file.php
+++ b/libraries/joomla/cache/storage/file.php
@@ -413,7 +413,7 @@ class JCacheStorageFile extends JCacheStorage
{
$time = @filemtime($path);
- if (($time + $this->_lifetime) < $this->_now || empty($time))
+ if (($time + $this->_lifetime) < $this->_now || empty($time) || filesize($path) === 0)
{
@unlink($path);
I will create a PR for above option 2.
Other solutions may require to catch each error as exception in the cache method and then delete the cache file or try to cache error response.
Hi @csthomas I have experienced another issue due to 'r+b' -> 'c+b' replacement.
Before this change, for a module included in an article with {loadmodule}, it was possible to call JCache::setCaching(false) to disable caching of the container article.
Now an empty file remains in the directory instead, which prevents subsequent view of the article until the cache expires.
Therefore I ask myself if 'c+b' is really necessary? What's the advantage of creating an empty file when you still don't need it?
Otherwise I'd suggest to restore the previous mode 'r+b'.
About creating an empty file.
flock()
, to prevent other php processes to create the same cache file in the same time.About your situation I understand that:
$view->display()
JCache::setCaching(false)
Take a look at #15592 it should resolve your problem.
@csthomas your description is so accurate that for a second, I was afraid that you control my PC with a malware.
I understand the need for file locking, but this way we have changed so deeply the behaviour of the file cache, that the problem reported up to now are just the first in a long line that I'm sure will be reported.
I think that the current implementation has a major architectural problem that was already there before your PR, and that can be resumed in "do not lock for longer than is strictly necessary".
Since we currently:
then it is reasonable to expect that something will go wrong.
Your attempt to fix it using the shutdown function is clever, but as you said, it's dirty.
To me it was badly designed before your PR, but the 'r+b' mode did prevent early lock.
It's one of those cases where two errors compensates each other.
Having changed the mode to 'c+b' has highlighted the problem.
I just wanted to know if you are agree with that, and I'll start a full refactoring.
Without any testing instructions this is unlikely to get tested very quickly
This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/10767.