nette / robot-loader

🍀 RobotLoader: high performance and comfortable autoloader that will search and autoload classes within your application.
https://doc.nette.org/robotloader
Other
871 stars 32 forks source link

subtle changes after fixing #11 #19

Closed deba12 closed 4 years ago

deba12 commented 4 years ago

Version: dev-master

Bug Description

After file locking changes in #11 we can't have read-only cache. We are getting errors like

PHP Warning:  fopen(/xxx/xxx/xxx//temp/3f6807b4367423b13920e6b4e953892d.php): failed to open stream: Permission denied in /xxx/xxx/xxx/vendor/nette/robot-loader/src/RobotLoader/RobotLoader.php on line 414

Warning: fopen(/xxx/xxx/xxx//temp/3f6807b4367423b13920e6b4e953892d.php): failed to open stream: Permission denied in /xxx/xxx/xxx/vendor/nette/robot-loader/src/RobotLoader/RobotLoader.php on line 414
PHP Fatal error:  Uncaught RuntimeException: Unable to create or acquire shared lock on file '/xxx/xxx/xxx//temp/3f6807b4367423b13920e6b4e953892d.php'. in /xxx/xxx/xxx/vendor/nette/robot-loader/src/RobotLoader/RobotLoader.php:416
Stack trace:
#0 /xxx/xxx/xxx/vendor/nette/robot-loader/src/RobotLoader/RobotLoader.php(77): Nette\Loaders\RobotLoader->loadCache()
#1 /xxx/xxx/xxx/noir-api/kernel.php(45): Nette\Loaders\RobotLoader->register()
#2 /xxx/xxx/xxx/app/cli/worker.php(21): require('/xxx/xxx/xxx...')
#3 {main}
  thrown in /xxx/xxx/xxx/vendor/nette/robot-loader/src/RobotLoader/RobotLoader.php on line 416

Fatal error: Uncaught RuntimeException: Unable to create or acquire shared lock on file '/xxx/xxx/xxx//temp/3f6807b4367423b13920e6b4e953892d.php'. in /xxx/xxx/xxx/vendor/nette/robot-loader/src/RobotLoader/RobotLoader.php:416
Stack trace:
#0 /xxx/xxx/xxx/vendor/nette/robot-loader/src/RobotLoader/RobotLoader.php(77): Nette\Loaders\RobotLoader->loadCache()
#1 /xxx/xxx/xxx/noir-api/kernel.php(45): Nette\Loaders\RobotLoader->register()
#2 /xxx/xxx/xxx/app/cli/worker.php(21): require('/xxx/xxx/xxx...')
#3 {main}
  thrown in /xxx/xxx/xxx/vendor/nette/robot-loader/src/RobotLoader/RobotLoader.php on line 416

file cache permissions are:

$ ls -la temp/3f6807b4367423b13920e6b4e953892d.php
-rw-r--r-- 1 app app 10913 Feb 24 16:26 temp/3f6807b4367423b13920e6b4e953892d.php

we have successfully used: on deploy we generate our class cache. web server is not allowed to change class cache file due permissions. Everything works fine until #11

Steps To Reproduce

generate cache with one user, and try to use it with another

Expected Behavior

To works like before

Possible Solution

revert everything until 180f89ebe6c11c1a409c2ded03cd40f6364530fa and it works like a charm

dg commented 4 years ago

@deba12 The patch I sent now b96d363 should fail at line 462, can you check it?

We will then try to find out if it is better to delete or rename the file first.

deba12 commented 4 years ago

sure,

PHP Warning:  fopen(/xxx/xxx/xxx//temp/f01f31d67a7ad6a40c9dfd30b8ed95be.php.lock): failed to open stream: Permission denied in /xxx/xxx/xxx/vendor/nette/robot-loader/src/RobotLoader/RobotLoader.php on line 418

Warning: fopen(/xxx/xxx/xxx//temp/f01f31d67a7ad6a40c9dfd30b8ed95be.php.lock): failed to open stream: Permission denied in /xxx/xxx/xxx/vendor/nette/robot-loader/src/RobotLoader/RobotLoader.php on line 418
PHP Fatal error:  Uncaught RuntimeException: Unable to create file '/xxx/xxx/xxx//temp/f01f31d67a7ad6a40c9dfd30b8ed95be.php.lock'. in /xxx/xxx/xxx/vendor/nette/robot-loader/src/RobotLoader/RobotLoader.php:420
Stack trace:
#0 /xxx/xxx/xxx/vendor/nette/robot-loader/src/RobotLoader/RobotLoader.php(77): Nette\Loaders\RobotLoader->loadCache()
#1 /xxx/xxx/xxx/noir-api/kernel.php(45): Nette\Loaders\RobotLoader->register()
#2 /xxx/xxx/xxx/app/cli/worker.php(21): require('/xxx/xxx/xxx...')
#3 {main}
  thrown in /xxx/xxx/xxx/vendor/nette/robot-loader/src/RobotLoader/RobotLoader.php on line 420
deba12 commented 4 years ago
$ ls -la temp/f01f31d67a7ad6a40c9dfd30b8ed95be.php*
-rw-r--r-- 1 app app 10717 Feb 25 11:29 temp/f01f31d67a7ad6a40c9dfd30b8ed95be.php
-rw-r--r-- 1 app app     0 Feb 25 11:29 temp/f01f31d67a7ad6a40c9dfd30b8ed95be.php.lock
dg commented 4 years ago

Oh, now I understand, the directory is not writable…

dg commented 4 years ago

This fix should work.

deba12 commented 4 years ago

Yes its fixed. Thank you