commercialhaskell/stack

"you don't have permission to modify this file" error on Windows

varosi opened this issue ยท 10 comments

Steps to reproduce

On Windows 10 x64 run:

  1. stack install ghc-mod

Expected

Not to have this problem. Eventually to retry internally if it cannot modify this file. I suspect that this is some kind of multi-threading problem with write accessing this file.

Actual

At some time you'll get on Windows (not every time, but often):

C:\sr\snapshots\fe0c6596\pkgdb\package.cache: you don't have permission to modify this file

If you retry the build - it continues and there is no problem. But on some larger projects two or three continues are needed. This is unacceptable on CI/CD systems or automatic retry mechanism should be implemented.

Stack version

$ stack --version
Version 1.5.1, Git revision 600c1f01435a10d127938709556c1682ecfd694e x86_64 hpack-0.17.1

Method of installation

  • Official binary

I also saw this error on windows boxes but my suspicion is that it happens due to antivirus. At least, currently used antivirus sometimes causes similar problems on msbuilds too.

I cannot switch off antivirus due to corporate policies. Could you, please, try to exclude antivirus stuff?

Can you please paste a stack build -v --cabal-verbose log of when this happens? I think this is being thrown by a ghc-pkg call, which in this case is invoked by Cabal. So what's happening here is quite out of the control of stack, and should either be fixed in Cabal or ghc.

I also run into this problem every now and then. It's hard to reproduce because, as mentioned, re-running the command usually succeeds. The only anti-virus I have installed is Windows Defender.

I think that Stack could have some kind of retry on some operations in case of such failure.

I also am running into this issue: I usually do a stack exec -- ghc-pkg unregister --force <some-package> and then run stack build again to fix the issue. It usually happens about 10 times out of a 100.

We also experience this in our Windows CI (AppVeyor).
Here are logs from our latest build that failed due to this problem:

Installing library in
    C:\TorXakis\.stack\snapshots\ddadf15f\lib\x86_64-windows-ghc-8.0.2\hspec-core-2.4.4-HfxBR0YrMu77yIMWFmbbw5
    Registering hspec-core-2.4.4...
    Cabal-simple_Z6RU0evB_1.24.2.0_ghc-8.0.2.exe:
    'C:\Users\appveyor\AppData\Local\Programs\stack\x86_64-windows\ghc-integersimple-8.0.2\bin\ghc-pkg.EXE'
    exited with an error:
    hspec-core-2.4.4: Warning: haddock-interfaces:
    C:\TorXakis\.stack\snapshots\ddadf15f\doc\hspec-core-2.4.4\hspec-core.haddock
    doesn't exist or isn't a file
    ghc-pkg.EXE: C:\TorXakis\.stack\snapshots\ddadf15f\pkgdb\package.cache: you
    don't have permission to modify this file

I have 2 more builds that failed due to this error just last week, all while building different packages. So the problem does look like how @varosi suspected:

I suspect that this is some kind of multi-threading problem with write accessing this file.

I will add -v --cabal-verbose to my feature branch builds to have the logs @mgsloan requested when it happens again.

this appears to be a duplicate of #2617

@cleverca22 Ah good point. So, to others in this thread, and readers from searches:

The likely workaround is to switch to GHC 8.2.1

This problem seems to be fixed on GHC 8.2.1, but there is another one which occurs the same way - randomly and prevent the build from finishing successfully. But it seems like it's another problem.

On latest GHCs I don't get this message.