haskell / cabal

Official upstream development repository for Cabal and cabal-install
https://haskell.org/cabal
Other
1.61k stars 691 forks source link

withFile: resource busy (file is locked) #10151

Open simonpj opened 3 months ago

simonpj commented 3 months ago
simonpj@LHR-WD-22561:~/code/horde-ad$ rm -rf /home/simonpj/.cabal/packages/head.hackage.ghc.haskell.org
simonpj@LHR-WD-22561:~/code/horde-ad$ cabal update
Warning: No mirrors found for https://ghc.gitlab.haskell.org/head.hackage/
Downloading the latest package lists from:
- hackage.haskell.org
- head.hackage.ghc.haskell.org
- head.hackage.ghc.haskell.org
/home/simonpj/.cabal/packages/head.hackage.ghc.haskell.org/01-index.timestamp: withFile: resource busy (file is locked)
simonpj@LHR-WD-22561:~/code/horde-ad$ 

I removed the directory, typed cabal update, and it complained about a locked file in that very directory.

Seems non-deterministic. Re-running cabal update sometimes works.

@Mikolaj found that cabal.project.local had the same entry twice. See below. Maybe that's the reason

repository head.hackage.ghc.haskell.org
   url: https://ghc.gitlab.haskell.org/head.hackage/
   secure: True
   key-threshold: 3
   root-keys:
       7541f32a4ccca4f97aea3b22f5e593ba2c0267546016b992dfadcd2fe944e55d
       26021a13b401500c8eb2761ca95c61f2d625bfef951b939a8124ed12ecf07329
       f76d08be13e9a61a377a85e2fb63f4c5435d40f8feb3e12eb05905edb8cdea89
repository head.hackage.ghc.haskell.org
   url: https://ghc.gitlab.haskell.org/head.hackage/
   secure: True
   key-threshold: 3
   root-keys:
       f76d08be13e9a61a377a85e2fb63f4c5435d40f8feb3e12eb05905edb8cdea89
       26021a13b401500c8eb2761ca95c61f2d625bfef951b939a8124ed12ecf07329
       7541f32a4ccca4f97aea3b22f5e593ba2c0267546016b992dfadcd2fe944e55d

allow-newer:
  Cabal,
  base,
  binary,
  bytestring,
  containers,
  deepseq,
  ghc,
  ghc-bignum,
  ghc-boot,
  ghc-boot-th,
  ghc-prim,
  integer-gmp,
  template-haskell,
  text,
  time

constraints:
  base installed,
  ghc installed,
  ghc-bignum installed,
  ghc-prim installed,
  integer-gmp installed,
  template-haskell installed

constraints:
  Cabal ==2.4.1.0 || ==3.0.2.0 || ==3.2.1.0,
  Cabal-syntax ==3.8.1.0,
  FPretty ==1.1,
  JuicyPixels ==3.3.8,
  ansi-pretty ==0.1.2.2,
  arith-encode ==1.0.2,
  aur ==7.0.7,
  aura ==3.2.9,
  barbies-th ==0.1.11,
  box-tuples ==0.2.0.4,
  cabal-doctest ==1.0.9,
  charsetdetect ==1.1.0.3,
  charsetdetect-ae ==1.1.0.4,
  chaselev-deque ==0.5.0.5,
  containers ==0.6.7 || ==0.6.8 || ==0.7,
  critbit ==0.2.0.0,
  crypto-random ==0.0.9,
  cryptol ==3.1.0,
  data-default-instances-new-base ==0.0.2,
  data-r-tree ==0.6.0,
  datetime ==0.3.1,
  derive-lifted-instances ==0.2.2,
  drinkery ==0.4,
  endo ==0.3.0.1,
  enumeration ==0.2.0,
  extra ==1.7.14,
  free-functors ==1.2.1,
  freer-simple ==1.2.1.2,
  ghc-lib-parser ==9.8.1.20231121,
  ghc-tcplugins-extra ==0.4.5,
  ghc-typelits-extra ==0.4.6,
  ghc-typelits-knownnat ==0.7.10,
  ghc-typelits-natnormalise ==0.7.9,
  ghcide ==2.6.0.0,
  haskell-src-meta ==0.8.13,
  haxl ==2.4.0.0,
  hgeometry ==0.14,
  hgeometry-combinatorial ==0.14,
  hgeometry-ipe ==0.13,
  hie-bios ==0.13.1,
  hls-plugin-api ==2.6.0.0,
  inj-base ==0.2.0.0,
  io-choice ==0.0.7,
  language-bash ==0.9.2,
  language-haskell-extract ==0.2.4,
  lens ==5.2.3,
  liquidhaskell-boot ==0.9.8.1,
  mainland-pretty ==0.7.1,
  monoidal-containers ==0.6.4.0,
  packman ==0.5.0,
  partial-isomorphisms ==0.2.3.0,
  pgp-wordlist ==0.1.0.3,
  refinery ==0.4.0.0,
  row-types ==1.0.1.2,
  salak ==0.3.6,
  sbv ==10.2,
  singletons ==3.0.2,
  singletons-base ==3.1.1,
  singletons-th ==3.1.1,
  siphash ==1.0.3,
  strict-containers ==0.2,
  text-short ==0.1.5,
  text-show ==3.10.5,
  th-abstraction ==0.5.0.0 || ==0.6.0.0,
  th-compat ==0.1.4,
  th-desugar ==1.14,
  th-lift ==0.8.4,
  th-orphans ==0.13.14,
  true-name ==0.1.0.3,
  typelits-printf ==0.2.0.0,
  vector-circular ==0.1.4,
  vector-space ==0.16,
  what4 ==1.5.1,
  winery ==1.4

constraints:
  optparse-applicative -process,
  tasty -unix
Mikolaj commented 3 months ago

I expect running the curl https://ghc.gitlab.haskell.org/head.hackage/cabal.project >> cabal.project.local command from https://ghc.gitlab.haskell.org/head.hackage/ twice is not an uncommon pitfall nowadays, so it would be useful if cabal errored out early or reacted more gracefully than racing with itself. :)

RyanGlScott commented 3 months ago

I've run into this too, except that I didn't repeat the repository head.hackage.ghc.haskell.org stanza, and running cabal update failed very deterministically for me. The only way I was able to fix the error was to delete ~/.cache/cabal/packages/head.hackage.ghc.haskell.org and run cabal update afterwards.

geekosaur commented 3 months ago

I get this every so often as well. I think it usually happens when I switch cabal version, but am not certain.

pranaysashank commented 1 month ago

@Mikolaj It happens to me too, it's indeed something to do with switch cabal versions. Here are some ways I manage to reproduce it, but it's not deterministic when the error happens.

In a haskell repo with a cabal.project,

1) rm -rf /tmp/cabal 2) cabal clean && rm cabal.project.freeze 3) CABAL_DIR=/tmp/cabal cabal-3.12.1.0 update 4) CABAL_DIR=/tmp/cabal cabal-3.10.3.0 build all --dry-run

Some times you'll already see the error at this point, however at other times you'll have to switch the version again and run update or some other action

5) CABAL_DIR=/tmp/cabal cabal-3.12.1.0 update

In the repo I reproduced this, we have an additional repository in our cabal.project. and the resource busy error always points to this additional repo's 01-index.tar

We encountered this when using https://github.com/MangoIV/cabal-audit with setup-haskell actions as the actions runs update with the latest release cabal, but cabal-audit seems to use an older cabal-install / Cabal library