snowleopard / hadrian

Hadrian: a new build system for the Glasgow Haskell Compiler. Now merged into the GHC tree!
https://gitlab.haskell.org/ghc/ghc/tree/master/hadrian
MIT License
208 stars 37 forks source link

package.cache: you don't have permission to modify this file #482

Open nh2 opened 6 years ago

nh2 commented 6 years ago

Just now I got this interesting error on Windows (on top of ghc/ghc@a1950e6dc03b560105903ad44050b1570f3bc24f):

...
/-------------------------------------------------------------------\
| Successfully built library 'ghc-prim' (Stage1, way v).            |
| Library: _build/stage1/libraries/ghc-prim/libHSghc-prim-0.5.2.0.a |
| Library synopsis: GHC primitives.                                 |
\-------------------------------------------------------------------/
| Run Tar Extract: libraries/integer-gmp/gmp/gmp-tarballs/gmp-6.1.2-nodoc.tar.bz2 => C:/Users/IEUser/AppData/Local/Temp/extra-dir-613326556233
| Copy file: libraries/integer-gmp/gmp/gmpsrc.patch => C:/Users/IEUser/AppData/Local/Temp/extra-dir-613326556233/gmpsrc.patch
| Apply patch C:/Users/IEUser/AppData/Local/Temp/extra-dir-613326556233/gmpsrc.patch
patching file gmp-6.1.2/configure
patching file gmp-6.1.2/Makefile.am
patching file gmp-6.1.2/Makefile.in
patching file gmp-6.1.2/configure.ac
patching file gmp-6.1.2/mpn/asm-defs.m4
| Move directory: C:/Users/IEUser/AppData/Local/Temp/extra-dir-613326556233/gmp-6.1.2 => _build/stage1/gmp
| Run Configure "_build/stage1/gmp": _build/stage1/gmp/Makefile.in => _build/stage1/gmp/Makefile
| Fix _build/stage1/libraries/base/package-data.mk
| Fix _build/stage1/libraries/base/inplace-pkg-config
| Run GhcPkg Update Stage1: _build/stage1/libraries/base/inplace-pkg-config => inplace/lib/package.conf.d/base-4.11.0.0.conf
base-4.11.0.0: Warning: haddock-interfaces: C:/Users/IEUser/ghc/_build/stage1/libraries/base\doc\html\base\base.haddock doesn't exist or isn't a file
| Run GhcCabal: libraries/filepath/filepath.cabal => _build/stage1/libraries/filepath/package-data.mk (and 1 more)
| Run GhcCabal: libraries/xhtml/xhtml.cabal => _build/stage1/libraries/xhtml/package-data.mk (and 1 more)
| Fix _build/stage1/libraries/filepath/package-data.mk
| Run GhcCabal: libraries/array/array.cabal => _build/stage1/libraries/array/package-data.mk (and 1 more)
| Run GhcCabal: libraries/transformers/transformers.cabal => _build/stage1/libraries/transformers/package-data.mk (and 1 more)
| Run GhcCabal: libraries/ghc-boot-th/ghc-boot-th.cabal => _build/stage1/libraries/ghc-boot-th/package-data.mk (and 1 more)
| Fix _build/stage1/libraries/filepath/inplace-pkg-config
| Fix _build/stage1/libraries/transformers/package-data.mk
| Run Cc FindCDependencies Stage1: libraries/base/cbits/iconv.c => _build/stage1/libraries/base/c/cbits/iconv.o.d
| Fix _build/stage1/libraries/array/package-data.mk
| Fix _build/stage1/libraries/xhtml/package-data.mk
| Run GhcPkg Update Stage1: _build/stage1/libraries/filepath/inplace-pkg-config => inplace/lib/package.conf.d/filepath-1.4.1.2.conf
| Run Cc FindCDependencies Stage1: libraries/base/cbits/sysconf.c => _build/stage1/libraries/base/c/cbits/sysconf.o.d
filepath-1.4.1.2: Warning: haddock-interfaces: C:/Users/IEUser/ghc/_build/stage1/libraries/filepath\doc\html\filepath\filepath.haddock doesn't exist or isn't a file
| Run Cc FindCDependencies Stage1: libraries/base/cbits/consUtils.c => _build/stage1/libraries/base/c/cbits/consUtils.o.d
| Run Cc FindCDependencies Stage1: libraries/base/cbits/WCsubst.c => _build/stage1/libraries/base/c/cbits/WCsubst.o.d
| Fix _build/stage1/libraries/ghc-boot-th/package-data.mk
| Fix _build/stage1/libraries/array/inplace-pkg-config
| Run Cc FindCDependencies Stage1: libraries/base/cbits/SetEnv.c => _build/stage1/libraries/base/c/cbits/SetEnv.o.d
| Run Cc FindCDependencies Stage1: libraries/base/cbits/Win32Utils.c => _build/stage1/libraries/base/c/cbits/Win32Utils.o.d
| Run Cc FindCDependencies Stage1: libraries/base/cbits/primFloat.c => _build/stage1/libraries/base/c/cbits/primFloat.o.d
| Run Cc FindCDependencies Stage1: libraries/base/cbits/CastFloatWord.cmm => _build/stage1/libraries/base/cmm/cbits/CastFloatWord.o.d
| Fix _build/stage1/libraries/ghc-boot-th/inplace-pkg-config
| Run Cc FindCDependencies Stage1: libraries/base/cbits/inputReady.c => _build/stage1/libraries/base/c/cbits/inputReady.o.d
| Fix _build/stage1/libraries/transformers/inplace-pkg-config
| Run Cc FindCDependencies Stage1: libraries/base/cbits/PrelIOUtils.c => _build/stage1/libraries/base/c/cbits/PrelIOUtils.o.d
| Run Ghc CompileCWithGhc Stage1: libraries/base/cbits/sysconf.c => _build/stage1/libraries/base/c/cbits/sysconf.o
| Run Cc FindCDependencies Stage1: libraries/base/cbits/DarwinUtils.c => _build/stage1/libraries/base/c/cbits/DarwinUtils.o.d
| Run GhcPkg Update Stage1: _build/stage1/libraries/ghc-boot-th/inplace-pkg-config => inplace/lib/package.conf.d/ghc-boot-th-8.3.conf
ghc-boot-th-8.3: Warning: haddock-interfaces: C:/Users/IEUser/ghc/_build/stage1/libraries/ghc-boot-th\doc\html\ghc-boot-th\ghc-boot-th.haddock doesn't exist or isn't a file
| Run Cc FindCDependencies Stage1: libraries/base/cbits/md5.c => _build/stage1/libraries/base/c/cbits/md5.o.d
| Fix _build/stage1/libraries/xhtml/inplace-pkg-config
| Run Ghc CompileCWithGhc Stage1: libraries/base/cbits/iconv.c => _build/stage1/libraries/base/c/cbits/iconv.o
| Run Ghc CompileCWithGhc Stage1: libraries/base/cbits/SetEnv.c => _build/stage1/libraries/base/c/cbits/SetEnv.o
| Run GhcPkg Update Stage1: _build/stage1/libraries/array/inplace-pkg-config => inplace/lib/package.conf.d/array-0.5.2.0.conf
| Run Ghc CompileHs Stage1: libraries/base/cbits/CastFloatWord.cmm => _build/stage1/libraries/base/cmm/cbits/CastFloatWord.o
| Run Ghc CompileCWithGhc Stage1: libraries/base/cbits/consUtils.c => _build/stage1/libraries/base/c/cbits/consUtils.o
| Run Ghc CompileCWithGhc Stage1: libraries/base/cbits/PrelIOUtils.c => _build/stage1/libraries/base/c/cbits/PrelIOUtils.o
| Run Ghc CompileCWithGhc Stage1: libraries/base/cbits/WCsubst.c => _build/stage1/libraries/base/c/cbits/WCsubst.o
| Run Ghc CompileCWithGhc Stage1: libraries/base/cbits/DarwinUtils.c => _build/stage1/libraries/base/c/cbits/DarwinUtils.o
| Run Ghc CompileCWithGhc Stage1: libraries/base/cbits/primFloat.c => _build/stage1/libraries/base/c/cbits/primFloat.o
| Run Ghc CompileCWithGhc Stage1: libraries/base/cbits/Win32Utils.c => _build/stage1/libraries/base/c/cbits/Win32Utils.o
| Run Ghc CompileCWithGhc Stage1: libraries/base/cbits/inputReady.c => _build/stage1/libraries/base/c/cbits/inputReady.o
| Run GhcPkg Update Stage1: _build/stage1/libraries/transformers/inplace-pkg-config => inplace/lib/package.conf.d/transformers-0.5.4.0.conf
| Run Ghc CompileCWithGhc Stage1: libraries/base/cbits/md5.c => _build/stage1/libraries/base/c/cbits/md5.o
array-0.5.2.0: Warning: haddock-interfaces: C:/Users/IEUser/ghc/_build/stage1/libraries/array\doc\html\array\array.haddock doesn't exist or isn't a file
transformers-0.5.4.0: Warning: haddock-interfaces: C:/Users/IEUser/ghc/_build/stage1/libraries/transformers\doc\html\transformers\transformers.haddock doesn't exist or isn't a file
| Run GhcPkg Update Stage1: _build/stage1/libraries/xhtml/inplace-pkg-config => inplace/lib/package.conf.d/xhtml-3000.2.2.conf
| Run GhcCabal: libraries/deepseq/deepseq.cabal => _build/stage1/libraries/deepseq/package-data.mk (and 1 more)
| Run GhcCabal: libraries/stm/stm.cabal => _build/stage1/libraries/stm/package-data.mk (and 1 more)
xhtml-3000.2.2: Warning: haddock-interfaces: C:/Users/IEUser/ghc/_build/stage1/libraries/xhtml\doc\html\xhtml\xhtml.haddock doesn't exist or isn't a file
ghc-pkg.exe: C:\Users\IEUser\ghc\inplace\lib\package.conf.d\package.cache: you don't have permission to modify this file
shakeArgsWith    0.000s    0%
Function shake   0.221s    0%
Database read    0.017s    0%
With database    0.032s    0%
Running rules  322.456s   99%  =========================
Total          322.726s   99%
Error when running Shake build system:
* inplace/lib/package.conf.d/xhtml-3000.2.2.conf
user error (Development.Shake.cmd, system command failed
Command: inplace/bin/ghc-pkg.exe update --force -v0 _build/stage1/libraries/xhtml/inplace-pkg-config
Exit code: 1
Stderr:
xhtml-3000.2.2: Warning: haddock-interfaces: C:/Users/IEUser/ghc/_build/stage1/libraries/xhtml\doc\html\xhtml\xhtml.haddock doesn't exist or isn't a file
ghc-pkg.exe: C:\Users\IEUser\ghc\inplace\lib\package.conf.d\package.cache: you don't have permission to modify this file
)

hadrian/build.stack.sh --configure -j --flavour=quickest  0.05s user 0.06s system 0% cpu 5:25.04 total

ls suggests I have permissions:

IEUser@MSEDGEWIN10 /c/Users/IEUser/ghc (git)-[remotes/nh2github/bug-8684-interruptible-hWaitForInput] % ls -lah inplace/lib/package.conf.d/package.cache
-rw-r--r-- 1 IEUser None 40K Nov 25 14:55 inplace/lib/package.conf.d/package.cache

Maybe it's something about some ghc-pkg invocations running in parallel on Windows, and that's not OK?

nh2 commented 6 years ago

My workaround is to just re-run it.

I'm using ghc-8.0.2 installed via stack.

snowleopard commented 6 years ago

@nh2 Thanks for reporting. I think I've seen this occasionally hitting CI, but I could never figure out why this happens. We use Shake resources to limit the number of parallel accesses to the package database, but presumably the error says that two processes collided when accessing package.conf.d/package.cache.

By the way, googling for package.conf.d\package.cache: you don't have permission to modify this file reveals quite a lot of similar reports outside of Hadrian. Could this be a GHC bug?

ndmitchell commented 6 years ago

GHC 8.0 was plagued by this problem - GHC 8.2 is vastly better, but it still happens occasionally. There's definitely GHC-level races on this file. I thought we were using Shake to avoid them, but I guess not entirely.

snowleopard commented 6 years ago

@ndmitchell Thanks! Do you think there is a GHC ticket for this problem? I tried to find an existing ticket, but only found a closed one.

ndmitchell commented 6 years ago

It's been closed since it got fixed in 8.2 :) Or at least it got mostly fixed, I still see it from time to time but it's a lot better at least.

snowleopard commented 6 years ago

I see :) Well, I'm tempted to close this issue then.

All: if you think we can somehow workaround this GHC bug in Hadrian, please reopen this issue.

ndmitchell commented 6 years ago

Does every GHC compile take the ghc-pkg reader lock? I think it should.

snowleopard commented 6 years ago

@ndmitchell Yes. GHC takes a readPackageDb resource, whereas ghc-pkg takes writePackageDb:

https://github.com/snowleopard/hadrian/blob/master/src/Rules.hs#L78-L81

This is not type-checked though, so we might have missed this somewhere. We could in principle make this more type-safe, but I'm not sure if this is worth it.

ndmitchell commented 6 years ago

Given it still fails we probably did miss something somewhere.

snowleopard commented 6 years ago

Hmm, I'll double check, but didn't you say above that it's a GHC bug? That is it got better in 8.2 but is still a bug that you've come across?

ndmitchell commented 6 years ago

It's long known issue in ghc-pkg that if you read/write concurrently to the package db it fails with the above error. See https://github.com/commercialhaskell/stack/issues/2617. GHC 8.2 made it a lot better, but I still don't think it's perfect. Hadrian works around it with reader/writer resources, but clearly the workaround isn't perfect either.

angerman commented 6 years ago

Can’t we fix this in ghc-pkg?

ndmitchell commented 6 years ago

It was fixed in ghc-pkg in 8.2. However, it still occurs occasionally for me so I suspect the fix is incomplete.

snowleopard commented 6 years ago

OK, I've reopened this issue. Let's check that our workaround this ghc-pkg issue covers all cases.

bgamari commented 6 years ago

I would far prefer to not workaround bugs in ghc-pkg and rather just fix them. Working around them just means they will remain hidden until some unfortunate user tries to use the compiler. @ndmitchell, can you open a ticket describing precisely what you have observed? ghc-pkg now (#13194) locks the database prior to modification so either the our locking logic is wrong or there is an unrelated bug.

ndmitchell commented 6 years ago

When detected it was reported, and fixed. The Hadrian workaround is required until 8.2 is the GHC boot version.

Since then I’ve had it some times, but never reproducibly or reliably, most often on a machine with aggressive anti virus. If I ever have it happen reliably I’ll ticket it.