Repository: NomicFoundation/hardhat

Issue #3722: Race condition in compiler download when more than one Hardhat process is compiling 
Created: 2023-02-27T19:43:38Z
Version of Hardhat
2.12.7
What happened?
We are using hardhat to compile and test our contracts. Everything was working fine, but recently sometimes when running build we got
Error: spawn /home/github/.cache/hardhat-nodejs/compilers-v2/linux-amd64/solc-linux-amd64-v0.8.16+commit.07a7930e EACCES
and right now it happens on nearly every run.
We are running it on self hosted runner with turborepo, so a few packages can be compiled at the same time (which i guess may be the cause of error, but everything was fine before)
Minimal reproduction steps
contracts-common:setup-build: > hardhat compile
contracts-common:setup-build:
contracts-common:setup-build: An unexpected error occurred:
contracts-common:setup-build:
contracts-common:setup-build: Error: spawn /home/github/.cache/hardhat-nodejs/compilers-v2/linux-amd64/solc-linux-amd64-v0.8.16+commit.07a7930e EACCES
contracts-common:setup-build:     at Process.ChildProcess._handle.onexit (node:internal/child_process:283:[19]
contracts-common:setup-build:     at onErrorNT (node:internal/child_process:478:16)
contracts-common:setup-build:     at processTicksAndRejections (node:internal/process/task_queues:83:[21] {
contracts-common:setup-build:   errno: -13,
contracts-common:setup-build:   code: 'EACCES',
contracts-common:setup-build:   syscall: 'spawn /home/github/.cache/hardhat-nodejs/compilers-v2/linux-amd64/solc-linux-amd64-v0.8.16+commit.07a7930e',
contracts-common:setup-build:   path: '/home/github/.cache/hardhat-nodejs/compilers-v2/linux-amd64/solc-linux-amd64-v0.8.16+commit.07a7930e',
contracts-common:setup-build:   spawnargs: [ '--standard-json' ],
contracts-common:setup-build:   cmd: '/home/github/.cache/hardhat-nodejs/compilers-v2/linux-amd64/solc-linux-amd64-v0.8.16+commit.07a7930e --standard-json'
contracts-common:setup-build: }
contracts-common:setup-build:  ELIFECYCLE  Command failed with exit code 1.
Search terms
solc, compile

Duplicate issue #4382: Concurrent download of solc compiler fails
Created: 2023-09-13T07:51:03Z
Version of Hardhat
2.17.3
What happened?
We are using Lerna in our monorepo, and we have 2 packages with contracts. A GitHub action is used to compile the packages when changes are pushed to the repo. This uses Lerna to concurrently compile the 2 packages with contracts. Both attempt to download the same compiler at the same time, and sometimes it fails. It seems a concurrency issue probably due to opening the file from 2 different threads.
We have a workaround in which we have a third dummy package with a dummy contract for the same compiler version. We first run the compilation of the dummy package, thus triggering the download of the compiler. Then when we compile the other 2 packages the compiler is already available and it works.
However this is a nasty approach that also adds a new dependency to our repo: every time we need to add a new compiler version to a package, we need to remember to add the same version to the dummy package so it downloads the proper compiler.
This bug was related, but it was never followed up: #1925
Minimal reproduction steps
Please find a reproduction repo with instructions here:
https://github.com/robercano/hardhat-concurrency-issue
Search terms
concurrent download lerna hardhat compiler

Closing comment (2023-09-26T12:49:26Z): Hey @robercano, thanks for this. I believe it's a duplicate of #3722 though. But your reproduction repo is better than mine, so I'm going to comment it in that issue.