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

Files locked in cache directory #525

Open
seydu opened this issue Feb 23, 2017 · 76 comments
Open

Files locked in cache directory #525

seydu opened this issue Feb 23, 2017 · 76 comments

Comments

@seydu
Copy link

seydu commented Feb 23, 2017

Expected behavior

Process should have write permission to a cache directory and all its sub-directories)

Actual behavior

When I start a container to run PHP FPM to serve Symfony2 some files in the cache directory are locked and the process cannot write in them. No way to remove remove the files (inside the container, in Windows using file explorer or Powershell, even when using Administrator privilege). When I stop Docker then I can remove the locked files.
For those familiar with Symfony2, this happens when Doctrine generates entity proxy class in temporary file and tries to rename it.

Information

  • Diagnostic ID: 1979D450-9549-4EDF-B258-1147D0CFAA65/2017-02-23_12-35-23
  • host distribution and version: OS: Windows 10 Enterprise Id: 1511 Build: 10586

Steps to reproduce the behavior

  1. ...
  2. ...
@dgageot
Copy link
Member

dgageot commented Feb 24, 2017

@seydu Would you have a compose file we could use to reproduce the issue?

@Toyinster
Copy link

+1 I have tried several ways to solve this but to no avail. I believe it is permission related:
I have added RUN usermod -u 1000 www-data to the dockerfile, and manually set the permissions on the storage folder inside the container but neither of these measures have solved it. Any help here would be much appreciated.

This is the php error message:
"rename(/opt/app/storage/proxies/__CG__DomainEntitiesOrganisation.php.58b29056532943.69863232,/opt/app/storage/proxies/__CG__DomainEntitiesOrganisation.php): No such file or directory"

@swels
Copy link

swels commented Apr 13, 2017

Same issue here - locked files - not only with php. Unlocks them only after Docker Settings -> Reset.
Can also cause very strage behavior in combination with git .. e.g. unable to checkout files, rm, reset etc.

I`m also unable to do chmod or chown on any mounted volume files - no effect.
This can be very frustrating for some setups.

Windows 10 Enterprise
Microsoft Windows [Version 10.0.14393]

Docker Community Edition
Version 17.03.1-ce-win5 (10743)
Channel: stable
b18e2a5

@chucky2305
Copy link

My colleague and i have the same problem.

e.g:
/var/cache/dev/twig/19/199fa6689b84659fb14bddcbeec7d0ea05230a4bf173fdf13fb488dc4b5642db.php

This file cannot be deleted. Wheter from Windows, nor inside any container (with root)

Windows 10 Pro
Docker Community Edition
Version 17.03.1-ce-win5 (10743)
Channel: stable
b18e2a5

@parkktech
Copy link

Same Here. It isn't super predictable or replicateable yet. But when building Magento2 sites in my local we have to often clean the pub directory and eventually each day the files will get locked and I have to restart docker to free them so I can delete and continue my work.
Windows 10 Pro
Docker w Moby VM Version 17.03.1-ce-win12 (12058)

@rpander93
Copy link

rpander93 commented Jun 6, 2017

Having exactly the same problem here. Problem occurs randomly to files generated by Doctrine, which are re-created on each request.

Windows 10 Pro with the latest Docker version

@jakubdrabik
Copy link

I have the same problem. Even after the container is killed, I must reset whole Docker to unlock the file.

Windows 10 Pro + the latest Docker version.

@therealdwright
Copy link

Also have this problem - npm creating locked files on the Windows Host. Can this be worked around with Docker Toolbox in the meantime?

@mrAndersen
Copy link

mrAndersen commented Jul 20, 2017

I have this issue too, in my case symfony can't rename or delete old doctrine cache fiel located in /var/www/symfony/var/cache/dev/doctrine/orm/Proxies/ locking all the project, only reboot helps, or changing cache directory to /tmp for example

@Rainbowlemon
Copy link

Rainbowlemon commented Jul 24, 2017

I'm getting the same issue with the same setup. Any ETA on a possible fix? I've come to a dead end at the project I'm working on because the ProxyGenerator is producing files that can't be changed or removed. Here's my logs:

Warning: rename(/var/www/project/app/cache/dev/doctrine/orm/Proxies/__CG__AppBundleEntityAddressCurrent.php.5975ffd4a9d748.71864046,/var/www/project/app/cache/dev/doctrine/orm/Proxies/__CG__AppBundleEntityAddressCurrent.php): No such file or directory

1. in vendor/doctrine/common/lib/Doctrine/Common/Proxy/ProxyGenerator.php at line 306 

304        file_put_contents($tmpFileName, $proxyCode);
305        @chmod($tmpFileName, 0664);
306        rename($tmpFileName, $fileName);
307    }

To add, the only way for me to remove the cache folder is the same as mrAndersen said above, by renaming the folder and then deleting it.

@KevinBon
Copy link

KevinBon commented Aug 9, 2017

Same here.

The issue show up when concurrent requests are called.

I run Docker for Windows with administrator privilege.

Windows 10 Pro
Docker Community Edition Version 17.07.0-ce-rc1-win21 (12927)

@BusterNeece
Copy link

Same exact problem here. Have verified that no other processes (backup tasks, etc) are accessing the files in the volume shared with the Docker container, and yet seemingly at random, files are being locked in very strange ways on the Windows host OS.

I had more than one case where the file appeared to Windows to have no owner information and to be unmodifiable, and only removing the Docker containers resolved the issue. Some other cases, the file just cannot be written to, but no explanation is given. Each situation is resolved completely by fully shutting down and removing the Docker containers.

I never encountered similar issues using Docker Toolbox and Virtualbox.

@dpgover
Copy link

dpgover commented Oct 5, 2017

I (and a lot of my co-workers) have the same issue. We are also using doctrine.
What I could get from all the cases we have of the problem, is that when two or more requests run at the same time, doctrine tries to generate those proxy files. Somehow, those processes collide trying to remove the proxy or one tries to delete the file and the other to access it. It happens more consistently when the parallel requests are ajax (no so sure why).

Once the files get locked, we have 4 strategies. Sometimes one works, sometimes does another:

  1. Stop and up the containers.
  2. Restart docker.
  3. Delete the HyperV VM and restart docker.
  4. Restart the PC (sometimes this does not even work)

I don't know what info we can provide that helps solving this issue.
We are using Win10 Pro 64bits.
Docker Comunity Edition 17.x (we have had this issue since version 12 or 13 I think)

Cheers.

@jaroslavlibal
Copy link

Same issue here with Doctrine in docker (proxies folder).

Docker for Windows 17.09.0-ce-win33 (13620)
Windows 10 Pro 1703

When I close the D4W app then the locked file disappears.

@Toshik
Copy link

Toshik commented Oct 10, 2017

Same here with npm install - files in .bin folder becomes locked, only Docker engine restart helps.

Version 17.09.0-ce-win33 (13620)
Channel: stable
8c56a3b

@jaroslavlibal
Copy link

Appears mostly when I send 2+ concurent requests to the webserver (eg. AJAX calls).

@dpgover
Copy link

dpgover commented Oct 23, 2017

@dgageot What info is needed that we can provide for the issue to advance...

Thanks!

@friism
Copy link

friism commented Oct 23, 2017

I'm guessing this happens for files that are bind-mounted from your Windows host into Docker containers?

If that's the case, you can maybe find a way to have the problematic files not be mapped to the Windows host and instead just be in the container or in a named volume (which won't touch the Windows filesystem).

As we make the transition to LCOW, we'll get a new and improved bind-mounting implementation: https://blog.docker.com/2017/09/preview-linux-containers-on-windows/

As that solution matures, you should check the behavior there, and we can work with Microsoft to fix things that are broken.

@k20human
Copy link

Same problem here with Symfony 3 and concurrent calls (REST API)
Some proxy files from doctrine are locked and not writeable ...

After a reboot of Docker i can remove the files

@liyo
Copy link

liyo commented Dec 2, 2017

Same issue with Doctrine Proxies files getting locked. After restarting Docker for Windows files can be removed but the issue persists.
Only workaround is to move proxy_dir out of the mounted project, ie. /tmp http://symfony.com/doc/3.3/reference/configuration/doctrine.html#doctrine-orm-configuration

@zeromodule
Copy link

I have a same problem with Docker for Windows, php-fpm, Doctrine and Symfony 3.
Doctrine proxies in cache directory getting locked and remain locked until a Docker restart occurs.

@darinrandal
Copy link

I'm having this same problem. We have a web application with nginx and it seems the most noticeable when switching branches with git (since it changes some files that are locked). It definitely seems like the problem gets worse when I start refreshing the site more causing some concurrency. I can confirm it clears the locks if I do docker-compose down and docker-compose up -d.

My only solution right now is before switching branches, clear all locked files via: Computer Management > System Tools > Shared Folders > Open Files > right click - disconnect all open files. You'll see all the files that are locked on this page and can clear them all easily without having to do down/up.

I'm not sure where to go from here but this problem is affecting everyone that works on this project, and with all the comments on this issue it definitely can't be an isolated incident.

@marhub
Copy link

marhub commented Feb 2, 2018

Same problem here. Can't generate doctrine proxies on docker runingo on windows 10.
One year have passed since OP added this ticket and still not resolved...

@dpgover
Copy link

dpgover commented Feb 2, 2018

I solved the issue using an internal directory created when building the container. I asume it can also be done using named volumes.
That works... if you don't need to have direct access to the generated files.
Since my problem was with Doctrine proxies, it works just fine leaving them inside the container.

@SeBsZ
Copy link

SeBsZ commented Feb 13, 2018

Same problem, usually when a long-running script is executing in my browser, and I try to do some Git actions (checkout, merge). The file will be in a weird state, readonly, can't delete, can't read. The only way is to completely exit Docker. On Windows.

@chris-cacciatore
Copy link

Same here on windows, we have a quite big script that rebuilds a lot of files, and sometimes it cannot delete a few of them, and my software just crashes. Even from windows, it is impossible to delete it, I have to reboot docker for windows and the file is then automatically deleted.

I can see that this issue has been open for more than a year now, is someone working on it? It is too much time-consuming for us, I seriously consider dropping docker and advising my team to go for another solution...

@digitalstraw
Copy link

/lifecycle frozen

@onigunn
Copy link

onigunn commented Apr 17, 2019

Encountering this problems in a php+nginx enviroment too.

/remove-lifecycle stale

@BusterNeece
Copy link

BusterNeece commented Apr 23, 2019

To share some additional information on exactly what's causing this issue on my end:

  • Inside a Docker container, a cron task is reading and executing PHP files to perform routine synchronization tasks;
  • The PHP files being used are bind-mounted to the Windows host, because they're actively being developed; and
  • At the same time as the container is trying to read a given PHP file, something out on the host computer is also trying to access that file (either Windows trying to index it, backup software trying to mess with it, or an IDE trying to save changes to it).

This causes the given conflicted file to enter a state of existential crisis, where it's not modifiable by any user on the host OS. I believe, but I'm not 100% confident, that at the same time, the guest container considers that file handle "stale".

Shutting down the Docker Desktop engine (and thus the Hyper-V VM) fixes the file's state and allows the host OS to modify it again.

It isn't possible in my case to completely disable cron tasks, though for development purposes I have reduced their frequency in the hopes that this will reduce the overall amount of time that the possible lockout conflict exists.

I have no idea what the underlying cause of this is, but I can reproduce it like clockwork on my end just by directly editing a file that the cron task is also reading at the same time, so if there's any debugging I can do, I'm happy to do so. This issue has plagued me for years and resulted in me going through a (very expensive) misadventure trying to find alternatives to Docker Desktop.

@blueamerican
Copy link

still an issue

@zpvini
Copy link

zpvini commented Jul 1, 2019

When the files were locked, I managed to unlock them in Windows > Computer Management > Shared Folders > Open Files.

Running the docker app as admin fixed the doctrine issue for me.

@digitalstraw
Copy link

digitalstraw commented Jul 2, 2019

In Doctrine also helps to set autoGenerateProxyClasses to false. It is not necessary to have this feature turned-on in local development on Windows, where this bug appears.

@blueamerican
Copy link

When the files were locked, I managed to unlock them in Windows > Computer Management > Shared Folders > Open Files.

Running the docker app as admin fixed the doctrine issue for me.

How do you run docker (desktop) as an admin?

@zpvini
Copy link

zpvini commented Jul 2, 2019

When the files were locked, I managed to unlock them in Windows > Computer Management > Shared Folders > Open Files.
Running the docker app as admin fixed the doctrine issue for me.

How do you run docker (desktop) as an admin?

Open the start menu, right click on Docker Desktop > More > Run as Administrator.

@blueamerican
Copy link

blueamerican commented Jul 2, 2019

run docker as an admin doesn't solve the issue for me.

@andrhevictor
Copy link

Moving proxies files to /tmp (if /tmp is not binded to your computer) folder solves the problem.
Just set:
'proxy_dir' => '/tmp'

@Lagily
Copy link

Lagily commented Aug 6, 2019

had the same issue, setting an absolute path made it work for us, e.g /var/www/html/doctrine_proxy/

@mkuehnel
Copy link

mkuehnel commented Aug 15, 2019

running docker as admin doesn't seem to fix the issue
@andrhevictor, @Lagily in which file do I have to put this config?

@Lagily
Copy link

Lagily commented Aug 15, 2019

I set it in the Doctrine PHP code config @mkuehnel

$config->setProxyDir('/path/to/myproject/lib/MyProject/Proxies');

https://www.doctrine-project.org/projects/doctrine-orm/en/2.6/reference/advanced-configuration.html

@HTMLGuyLLC
Copy link

HTMLGuyLLC commented Aug 26, 2019

This is terrible. My macbook is having the battery replaced so I'm on my windows desktop for the first time in 2 years and Symfony was running extremely slow (30+ seconds per request), so I tried setting up docker. Spent half a day yesterday getting it running just to see slow speeds and now files that I can't remove from the Proxies folder without restarting my computer (the same issue as people above). I can't believe this hasn't been solved in 2 years..

@HTMLGuyLLC
Copy link

HTMLGuyLLC commented Aug 26, 2019

FYI, if you don't use Doctrine PHP config, you can change the yaml file:
config\packages\doctrine.yaml

doctrine:
    orm:
        proxy_dir: '/var/www/MYPROJECT/var/cache/dev/doctrine/orm/Proxies'

@digitalstraw
Copy link

This is terrible. My macbook is having the battery replaced so I'm on my windows desktop for the first time in 2 years and Symfony was running extremely slow (30+ seconds per request), so I tried setting up docker. Spent half a day yesterday getting it running just to see slow speeds and now files that I can't remove from the Proxies folder without restarting my computer (the same issue as people above). I can't believe this hasn't been solved in 2 years..

You can just set autoGenerateProxyClasses: false in your Doctrine local development (non-production) configuration. It helps...

@HTMLGuyLLC
Copy link

Thanks @digitalstraw - My main page was loading but ajax calls were failing without this, but now the initial page load times out.

@HTMLGuyLLC
Copy link

HTMLGuyLLC commented Aug 26, 2019

Hmmm...after a few refreshes I got this (I suspect I need to manually recreate my cache now? Trying that):

Compile Error: Doctrine\Common\Proxy\AbstractProxyFactory::getProxyDefinition(): Failed opening required '/var/www/[MY_PROJECT]/var/cache/dev/doctrine/orm/Proxies/__CG__AppEntity[MY_ENTITY].php' (include_path='.:/usr/local/lib/php')

Gawd...just deleted my cache folder and it's 26.1 mb.

@digitalstraw
Copy link

Hmmm...after a few refreshes I got this:

Compile Error: Doctrine\Common\Proxy\AbstractProxyFactory::getProxyDefinition(): Failed opening required '/var/www/[MY_PROJECT]/var/cache/dev/doctrine/orm/Proxies/__CG__AppEntity[MY_ENTITY].php' (include_path='.:/usr/local/lib/php')

Try to delete the cache and run again. If it does not help, consider installing APC extension and configure Doctrine like this:

metadataCache: apcu
queryCache: apcu

@HTMLGuyLLC
Copy link

@digitalstraw - Just restarted, cleared cache, turned off docker, and turned on WAMP. I don't think the issue is docker-specific.

Warning: rename(C:\localhost\[MY_PROJECT]\var\cache\dev/doctrine/orm/Proxies\__CG__AppEntity[MY_ENTITY].php.5d63fc86847769.03751247,C:\localhost\[MY_PROJECT]\var\cache\dev/doctrine/orm/Proxies\__CG__AppEntityS[MY_ENTITY].php): Access is denied. (code: 5)

@HTMLGuyLLC
Copy link

doctrine/common#327

@davclark
Copy link

It seems this issue has veered a bit from the initial problem. So, I'm happy to open another issue.

In any case, I have recently had a couple different scenarios where lock files got permanently "stuck" unless docker for windows was stopped (even resetting didn't fix the issue as long as Docker was running). This happened twice with Git operations inside a container on a bind-mount, and once with my own lockfile (set from redis / rq) again on a bind-mounted directory.

Any pointers on how to avoid this would be greatly appreciated. We can try to change how we do the lock in RQ, and could change the version of git we're using perhaps?

@digitalstraw
Copy link

@davclark My files get stuck always when I run one script operating over one set of filesystem files in several parallel instances/requests. Files get stuck, then. Not all, some of them. So maybe if you avoid parallel access to one file, you might avoid this...

@spaceneenja
Copy link

I get similar issues when trying to npm install. Oddly this didn't appear until the past several weeks.

This seems part of to be a whole family of problems with LCOW that surface after some update or another and not really related to Docker Desktop.

@davclark
Copy link

Thanks @digitalstraw - though I am a bit loathe to patch both git and redis/rq to change their file locking behavior!

@davclark
Copy link

davclark commented Apr 2, 2020

I saw that 2.2.3.0 had a bunch of changes to bind mounts. But I didn't see anything regarding this issue. Are there any updates in that 2.2.3 or the near future? The urgency of this issue goes up now that WSL2 is the default in 2.2.3 - which I think means that stable channel gets WSL2 as default in June.

@dthree
Copy link

dthree commented Feb 11, 2021

Same exact issue but on OSX. Similarly restarting docker fixed it.

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

No branches or pull requests