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 · 13 comments
Closed

saveCache does not use lock #11

matej21 opened this issue Jul 17, 2017 · 13 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
Copy link
Member

@dg dg commented Jul 17, 2017

Do you have an idea how to solve it?

@JanTvrdik
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

@JanTvrdik
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
Copy link
Member

@dg dg commented Nov 28, 2017

Can you fix it somehow?

@ondrejmirtes
Copy link

@ondrejmirtes ondrejmirtes commented Feb 12, 2020

I'm experiencing this often when implementing parallel analysis in PHPStan. But only on Windows. I think it might be because the system only allows one process to write to a file at a time, so the rename() sometimes isn't successful.

@dg
Copy link
Member

@dg dg commented Feb 12, 2020

It seems that file cannot be deleted / renamed on Windows if it is open. So when PHP is reading it (include $file), renaming will fail.

So I'll use read lock.

@paveljanda
Copy link

@paveljanda paveljanda commented Feb 21, 2020

Sadly, on our projects, robot-loader stopped working in gitlab CI pipeline after updating package to 3.2.2:

Unable to create or acquire shared lock on file '/builds/.......some-package...../tests/integration/../../tests/temp/cache/nette.application/dc419f19af  
   b02aef8183855ed290885d.php

I will provide further details if needed.

@dg
Copy link
Member

@dg dg commented Feb 21, 2020

😐😣😫😭😭😭

@dakorpar
Copy link

@dakorpar dakorpar commented Feb 25, 2020

In my case issue is with dg/bypass finals:

Warning: file_get_contents(/home/circleci/repo/tests/unit/../../temp/tests/cache/nette.application/c68fd0a35afa3563c5a64085f36d239d.php): failed to open stream: No such file or directory in /home/circleci/repo/vendor/dg/bypass-finals/src/BypassFinals.php on line 205

@dg
Copy link
Member

@dg dg commented Feb 25, 2020

@dakorpar on Windows or Linux?

@dakorpar
Copy link

@dakorpar dakorpar commented Feb 25, 2020

doesn't really matter I get it everywhere...

  • ci on linux
  • wsl on windows
  • windows

also same thing with dev-master, for now I locked versions to 3.2.1

@dg
Copy link
Member

@dg dg commented Feb 26, 2020

I tried to change the implementation, it should not do it anymore.

@ondrejmirtes
Copy link

@ondrejmirtes ondrejmirtes commented Feb 26, 2020

I'll use RobotLoader's dev-master in the next release again and we'll see.

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

No branches or pull requests

6 participants