FS#77326 - [ghc-libs] version upgrades can result in bad ghc-pkg database

Attached to Project: Community Packages
Opened by Doug Patti (dpatti) - Sunday, 29 January 2023, 22:56 GMT
Last edited by Buggy McBugFace (bugbot) - Saturday, 25 November 2023, 20:05 GMT
Task Type Bug Report
Category Packages
Status Closed
Assigned To Felix Yan (felixonmars)
Architecture All
Severity Medium
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No

Details

Description:

The package.cache file that comes packaged with ghc-libs will sometimes not correctly be rebuilt after an install, leaving ghc in a bad state.

Additional information:

I did a system upgrade recently which included the bump from 9.0.2-1 -> 9.0.2-2. When I rebooted, xmonad failed to recompile because of missing dependencies. After a fairly thorough investigation, I realized the cause: on installation, the ghc-libs package writes out a package.cache file in /usr/lib/ghc-9.0.2/package.conf.d/ with the packages that existed at build time. The way `ghc-pkg` seems to work is: if all the *.conf files in the directory are older than the package.cache file, it is assumed up-to-date. You can find this in the source code [1], but you can also see this in action in the output of `ghc-pkg list -v2` (which increases verbosity):

GHC package manager version 9.0.2
Timestamp 2023-01-05 23:18:48 UTC for /usr/lib/ghc-9.0.2/package.conf.d/package.cache
WARNING: cache is out of date: /usr/lib/ghc-9.0.2/package.conf.d/package.cache
ghc will see an old view of this package db. Use 'ghc-pkg recache' to fix.
Timestamp 2023-01-29 18:31:49.281672821 UTC for /usr/lib/ghc-9.0.2/package.conf.d/vector-0.13.0.0-dBvEOJ9xPHLRlUgE
reading package config: /usr/lib/ghc-9.0.2/package.conf.d/vector-0.13.0.0-dBvEOJ9xPHLRlUgENbcJF.conf
...

You can note that the timestamp in the above output is January 5th, 2023, which is when the ghc-libs-9.0.2-2 package was built. The above output is what I get if I were to re-install ghc-libs at this version right now. However, when I upgraded to 9.0.2-2, the last time I did a system upgrade that resulted in a ghc-register.hook firing (which would have touched some conf file) was 2022-12-31. This meant that when I originally installed ghc-libs-9.0.2-2, it blew away my cache, and because that system upgrade did not contain an update for *every* haskell library, all the ones that didn't get updated never got re-registered. Those that did get updated were registered, but they often referenced packages that did not exist.

See also  FS#77311   FS#77312  which spawned from this confusion.

[1]: https://github.com/ghc/ghc/blob/ghc-9.0.2-release/utils/ghc-pkg/Main.hs#L888-L889

Steps to reproduce:

I put together a simple repro:

$ sudo touch -m -t 202212311217 /usr/lib/ghc-9.0.2/package.conf.d/*.conf
$ sudo pacman -U ghc-libs-9.0.2-2-x86_64.pkg.tar.zst
$ ghc-pkg list

Note the minimal package list. You can fix with:

$ ghc-pkg recache
$ ghc-pkg list
This task depends upon

Closed by  Buggy McBugFace (bugbot)
Saturday, 25 November 2023, 20:05 GMT
Reason for closing:  Moved
Additional comments about closing:  https://gitlab.archlinux.org/archlinux/p ackaging/packages/ghc/issues/1
Comment by Doug Patti (dpatti) - Sunday, 29 January 2023, 22:59 GMT
(I realize this should possibly have [ghc-libs] in the title instead, but I started writing the issue before I fully investigated, and I forgot to update the title. Sorry!)
Comment by Felix Yan (felixonmars) - Monday, 30 January 2023, 07:59 GMT
Thanks for the details! I'll try to run `ghc-pkg recache` on the else branch of ghc-libs' post_upgrade() and see if this fixes it.
Comment by Felix Yan (felixonmars) - Monday, 30 January 2023, 09:42 GMT
Please try again with ghc-libs 9.0.2-3.
Comment by Doug Patti (dpatti) - Tuesday, 31 January 2023, 03:09 GMT
This looks like a good fix, thanks! There's maybe something to note, though, which I will try describing with my example:

1. Sysupgrade installs new ghc-libs (9.0.2-2), and many other Haskell packages. Because of the issue with the cache noted here, the package.cache file does not have every package listed; only the core packages and those that were upgraded in this run, since their register hooks ran.

2. Time passes, sysupgrade again. This time you get a few more haskell packages. Some of these packages were not upgraded before. The unregister hook fails with an error like "ghc-pkg: cannot find package digest-0.0.1.4" which you can find in /var/log/haskell-register.log -- this is because that entry was not in the package.cache after the last sysupgrade. After the package is updated, the register hook runs and succeeds.

3. At this point, your package.cache thinks it knows about digest-0.0.1.5, which it does. But there still also exists a .conf file in package.conf.d/ for digest-0.0.1.4 because the unregister failed.

4. Sysupgrade picks up ghc-libs-9.0.2-3, which runs `ghc-pkg recache` at the end. At this point, it scans the package.conf.d/ directory and tries to register the old digest-0.0.1.4 which references a library that no longer exists.

Unfortunately, I don't really know how or if you could fix this. For me, I had to delete the .conf file that corresponded to digest-0.0.1.4 and run `ghc-pkg recache` again. But out of the 216 haskell packages I have, this was the only one that got into a bad state. I also don't know think I figured out what the downside of being in that state was -- I know that `ghc-pkg check` was making some noise, but maybe everything else just worked fine? I hope that makes sense! If not, I can try and give the steps to a more explicit repro.

Loading...