-
Notifications
You must be signed in to change notification settings - Fork 841
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
Power failure during stack build
results in corruption to global Stack directory
#3248
Comments
This is really unfortunate, I've had similar enough problems to understand the annoyance.
Agreed, to the extent possible. We should mark the package as compiled only after it's built—but without a transactional filesystem, it's not obvious the order of operations will be preserved. There might be an atomic API which doesn't require syncing the whole disk, but I'm not sure which. I used to think Also, building out of ~/.stack and moving outputs into place might help (assuming this is atomic enough), but it might not be easy, since the target installation path is an input to the compilation—I forget when and where you can move files.
Details are tricky. What's an easy way to verify the integrity of some binary output, without having to write new code to parse binary files? If your analysis is correct, a checksum won't help here. It will only help if Stack fully compiles and checksums the library originally and them something else modifies it — but Stack never modifies output. Also, to some extent this is probably GHC's fault. Press Ctrl-C while building the local project and you can get in a similar situation—it's enough that one of the |
Just to add to this — I frequently get emergency shutdowns for overheating on my laptop when compiling things with |
I agree with @Blaisorblade 's analysis that this is likely an issue with upstream tools that stack invokes. As far as I know, all of stack's own file IO is resistant to this sort of problem, since all it writes are caches that get discareded if they are unreadable. |
@garry-cairns That's unfortunate—you might want to disable parallel builds via |
@Blaisorblade thanks I'll try that |
@Blaisorblade Actually the best strategy seems to be to keep the parallel builds but manually cancel the build every 15-20 points in the progress tracker and let the system cool down. |
Not true at all. The critical window of failure occurs after the binary file has been closed, but not yet fully synced to disk. During this time, a coherent view of the file's entire content is nevertheless available to readers, and if a checksum were then to be calculated, it would represent what data is supposed to be there after a successful filesystem sync. In the case where some unsynced data did not survive a power failure, the checksum will either be missing or it will differ from that of the binary file on disk; in either case, it will provide a strong indication that the package should be rebuilt. |
@blipvert Fair enough, if that's indeed what's happening (not that I can imagine anything else). |
We've done some work in the direction of fixing this in GHC and stack, see #4559. |
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:
stack build conduit-combinators
is a no-op, because Stack thinks the library is already compiledstack 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 bystack build
. This needs to be repeated for each package that demonstrates the error.Expected behaviour
Stack version
Running on Sabayon Linux amd64 on btrfs, using kernel 4.9.30.
Method of installation
The text was updated successfully, but these errors were encountered: