commercialhaskell / commercialhaskell/stack
Power failure during `stack build` results in corruption to global Stack directory
- Dominant language
- Haskell
- Stars
- 4.1k
- Forks
- 850
- Avg merge
- 10h 37m
- Merged PRs (30d)
- 4
Description
### General summary/comments (optional)
If a power failure occurs while `stack build` is compiling a library, the incomplete files are stored in `~/.stack` but the package is marked as compiled. This means that any attempt to compile projects depending on it will fail.
Output when trying to compile a project using the library:
```
/home/reuben/project_sigma/src/Main.hs:4:1: error:
Bad interface file: /home/reuben/.stack/snapshots/x86_64-linux-tinfo6-nopie/lts-8.21/8.0.2/lib/x86_64-linux-ghc-8.0.2/conduit-combinators-1.1.1-BCs1IpMatSe9TKW4okLeA/Conduit.hi
Data.Binary.getWord8: end of file
/home/reuben/project_sigma/src/Main.hs:7:1: error:
Failed to load interface for ‘Data.Conduit.CSV’
Perhaps you meant
Data.Conduit (from conduit-1.2.11)
Data.Conduit.Lazy (from conduit-extra-1.1.16)
Data.Conduit.Lift (from conduit-1.2.11)
Use -v to see a list of the files searched for.
-- While building package sigma-0.1.0.0 using:
/home/reuben/.stack/setup-exe-cache/x86_64-linux-tinfo6-nopie/Cabal-simple_mPHDZzAJ_1.24.2.0_ghc-8.0.2 --builddir=.stack-work/dist/x86_64-linux-tinfo6-nopie/Cabal-1.24.2.0 build exe:sigma --ghc-options " -ddump-hi -ddump-to-file"
Process exited with code: ExitFailure 1
```
* `stack build conduit-combinators` is a no-op, because Stack thinks the library is already compiled
* deleting the directory for conduit-combinators doesn't fix the problem, only changes the error.
* `stack exec ghc-pkg check` does not detect the problem (unless you delete the directory)
### Workaround
The simplest solution is to simply delete `~/.stack`, but that requires an expensive rebuild.
A more efficient workaround is to run `stack exec ghc-pkg unregister conduit-combinators-1.1.1`, followed by `stack build`. This needs to be repeated for each package that demonstrates the error.
### Expected behaviour
* the packages should not actually be marked as having completed compilation until the output files have been synced to disk
* it would help if stack had a command that could verify the integrity of compiled libraries (e.g. a checksum) and recompile those which failed the integrity check
### Stack version
```
$ stack --version
Version 1.4.0, Git revision e714f1dd3fade19496d91bd6a017e435a96a6bcd (4640 commits) x86_64 hpack-0.17.0
```
Running on Sabayon Linux amd64 on btrfs, using kernel 4.9.30.
### Method of installation
* compiled from source
Contributor guide
Assessment
This issue has not been assessed yet.