cashapp / hermit

🐚 Hermit manages isolated, self-bootstrapping sets of tools in software projects.
https://cashapp.github.io/hermit
Apache License 2.0
600 stars 52 forks source link

Race condition when bootstrapping a single binary #391

Closed orestisfl closed 12 months ago

orestisfl commented 12 months ago

Reproduction instructions: Init/source a hermit environment and try to use a command that needs to be downloaded. When this command is run in parallel some invocations of it fail. My guess is that hermit tries to download it multiple times and ends up in a race condition.

$ hermit --version
v0.38.0 (stable)
$ hermit init
info: Creating new Hermit environment in /tmp/xx
info:   -> /tmp/xx/bin/activate-hermit
info:   -> /tmp/xx/bin/hermit
info:   -> /tmp/xx/bin/README.hermit.md
info:   -> /tmp/xx/bin/hermit.hcl
info: 

Hermit environment initialised in /tmp/xx

To activate the environment run:

  . /tmp/xx/bin/activate-hermit

Then run the following to list available commands:

  hermit --help

To deactivate the environment run:

  deactivate-hermit

For more information please refer to https://github.com/cashapp/hermit

$ source bin/activate-hermit
Hermit environment /tmp/xx activated
$ hermit install shfmt
info:shfmt-3.7.0:install: Installing shfmt-3.7.0
$ shfmt --version
$ rm -rf ~/.cache/hermit/pkg/shfmt*
$ for i in {1..5}; do shfmt --version& done
[2] 3273244
[3] 3273245
[4] 3273246
[5] 3273247
[6] 3273248
v3.7.0
[3]    3273245 done       shfmt --version
xx🐚 
fatal:hermit: destination /home/orestis/.cache/hermit/pkg/shfmt-3.7.0 already exists

[2]    3273244 exit 1     shfmt --version
fatal:hermit: destination /home/orestis/.cache/hermit/pkg/shfmt-3.7.0 already exists
fatal:hermit: destination /home/orestis/.cache/hermit/pkg/shfmt-3.7.0 already exists
[6]  + 3273248 exit 1     shfmt --version
[4]  - 3273246 exit 1     shfmt --version
fatal:hermit: destination /home/orestis/.cache/hermit/pkg/shfmt-3.7.0 already exists
[5]  + 3273247 exit 1     shfmt --version

Related: https://github.com/cashapp/hermit/issues/144

alecthomas commented 12 months ago

Thanks for the great bug report, should be fixed now.

orestisfl commented 11 months ago

Thank you for the quick fix and release!