Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/sweet-seas-shake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"hardhat": patch
---

Allow multiple parallel downloads of different compilers ([7946](https://github.com/NomicFoundation/hardhat/pull/7946)).
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ export class CompilerDownloaderImplementation implements CompilerDownloader {
readonly #compilersDir: string;
readonly #downloadFunction: typeof download;

readonly #mutexCompiler = new MultiProcessMutex("compiler-download");
readonly #mutexCompilerList = new MultiProcessMutex("compiler-download-list");

/**
Expand Down Expand Up @@ -200,11 +199,14 @@ export class CompilerDownloaderImplementation implements CompilerDownloader {
}

public async downloadCompiler(version: string): Promise<boolean> {
// Since only one process at a time can acquire the mutex, we avoid the risk of downloading the same compiler multiple times.
// This is because the mutex blocks access until a compiler has been fully downloaded, preventing any new process
// from checking whether that version of the compiler exists. Without mutex it might incorrectly
// return false, indicating that the compiler isn't present, even though it is currently being downloaded.
return this.#mutexCompiler.use(async () => {
// A per-version mutex ensures that only one process at a time can download a given compiler version,
// while still allowing different compiler versions to be downloaded in parallel.
// Without the mutex, a concurrent process might check whether a version exists, incorrectly
// find it missing (because another process is still downloading it), and start a redundant download.

const mutex = new MultiProcessMutex(`compiler-download-${version}`);

return mutex.use(async () => {
const isCompilerDownloaded = await this.isCompilerDownloaded(version);

if (isCompilerDownloaded === true) {
Expand Down
Loading