Skip to content
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

Deadlock while loading another cache in fallback of load() #54

Open
Vlczech opened this issue Feb 4, 2018 · 4 comments
Open

Deadlock while loading another cache in fallback of load() #54

Vlczech opened this issue Feb 4, 2018 · 4 comments

Comments

@Vlczech
Copy link

Vlczech commented Feb 4, 2018

  • bug report? yes
  • feature request? no
  • version: 2.5.6 (nette/caching)

Description

When trying to load cache by fallback in another fallback of load, script runs to infinity (maybe deadlock?)

Steps To Reproduce

public function runMethodWithCache() {
$cachedValue1 = $this->cache->load('cached_value_1', function(& $dependencies) {
        $dependencies['expire'] = '+1 day';
        $value = $this->runAnotherMethodWithCache();        
        return $value;
      });
}

private function runAnotherMethodWithCache() {
      $usedValue = 'something';
      $this->someValue = $this->cache->load('cached_value_2', function (& $dependencies) use ($usedValue) {
        $dependencies[Cache::ITEMS] = ['cached_value_1'];
        return $usedValue;
      });

     return 'something another';
}

When I comment following lines from second method, script running as expected.

      $this->someValue = $this->cache->load('cached_value_2', function (& $dependencies) use ($usedValue) {
        $dependencies[Cache::ITEMS] = ['cached_value_1'];
        return $usedValue;
      });

[UPDATE 1]: most probably, this is caused by cross dependency of Cache::ITEMS in second method, which is dependent on first one cache.

Idea

If subloading of cache is not possible, it should be inspect to avoid sub-loading of cache.

@JanTvrdik
Copy link
Contributor

This is imho expected behavior, dependencies must form directed acyclic graph.

@dg
Copy link
Member

dg commented Feb 6, 2018

Can you fix it and send a PR?

@Vlczech
Copy link
Author

Vlczech commented Mar 2, 2018

@dg I can try to fix it, but it will not be soon.

@dg
Copy link
Member

dg commented Mar 2, 2018

It is ok

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants