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

saveCache does not use lock #11

Closed
matej21 opened this issue Jul 17, 2017 · 4 comments
Closed

saveCache does not use lock #11

matej21 opened this issue Jul 17, 2017 · 4 comments

Comments

@matej21
Copy link

@matej21 matej21 commented Jul 17, 2017

  • bug report? yes
  • version: 3.0.1

saveCache does not use lock and therefore it may fail on this line with following error

E_WARNING: rename(/root/ss/temp/tests/cache/Nette.RobotLoader/b118fb0ce0dea7bbc63b1ce28466196d.php.tmp,/root/ss/temp/tests/cache/Nette.RobotLoader/b118fb0ce0dea7bbc63b1ce28466196d.php): No such file or directory
   
   in /root/ss/vendor/nette/robot-loader/src/RobotLoader/RobotLoader.php(414) rename()
   in /root/ss/vendor/nette/robot-loader/src/RobotLoader/RobotLoader.php(96) Nette\Loaders\RobotLoader->saveCache()
   in [internal function]Nette\Loaders\RobotLoader->tryLoad()
   in [internal function]spl_autoload_call()
....
@dg

This comment has been minimized.

Copy link
Member

@dg dg commented Jul 17, 2017

Do you have an idea how to solve it?

@JanTvrdik

This comment has been minimized.

Copy link
Contributor

@JanTvrdik JanTvrdik commented Jul 17, 2017

Any of the following should work

  1. use lock
  2. use @rename(...) + is_file check in case of failure I changed my mind. This won't work.
  3. generate random suffix for temporary file
@dg dg closed this in 6972dbf Jul 17, 2017
dg added a commit that referenced this issue Jul 18, 2017
@JanTvrdik

This comment has been minimized.

Copy link
Contributor

@JanTvrdik JanTvrdik commented Nov 26, 2017

Unfortunately, it still does not seem to work reliably.

To replicate it's enough to run the following scripts multiple time in parallel after temp directory has been clear.

<?php declare(strict_types = 1);

require __DIR__ . '/../../vendor/autoload.php';

$loader = new Nette\Loaders\RobotLoader;
$loader->setAutoRefresh(true);
$loader->setTempDirectory(__DIR__ . '/../temp');
$loader->addDirectory(__DIR__);
$loader->register();

assert(class_exists(Foo::class) === true);
assert(class_exists(Unknown::class) === false);

Occasionally it fails with error

Warning: rename(.../temp/aed3679f15f72267b5350e48491c0e0e.phpefeebef3986753080eda337bc0681ea6.tmp,.../temp/aed3679f15f72267b5350e48491c0e0e.php): Access is denied. (code: 5) in ...\vendor\nette\robot-loader\src\RobotLoader\RobotLoader.php on line 415

(I tried using random_bytes instead of uniqid but it make no difference)

@dg

This comment has been minimized.

Copy link
Member

@dg dg commented Nov 28, 2017

Can you fix it somehow?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.