From 45025fbbb3381351f9f3cf4cdaf0afd39aa3d77b Mon Sep 17 00:00:00 2001 From: Franco Victorio Date: Tue, 27 Jun 2023 13:47:01 +0200 Subject: [PATCH 1/2] Consume downloads instead of piping them This is a workaround for an issue related to node v18.16.0, the stream module and undici. See https://github.com/nodejs/undici/issues/2173 for the details. --- packages/hardhat-core/src/internal/util/download.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/packages/hardhat-core/src/internal/util/download.ts b/packages/hardhat-core/src/internal/util/download.ts index 7151b71606..eb5b5811cc 100644 --- a/packages/hardhat-core/src/internal/util/download.ts +++ b/packages/hardhat-core/src/internal/util/download.ts @@ -1,9 +1,7 @@ import type { Dispatcher } from "undici"; -import fs from "fs"; import fsExtra from "fs-extra"; import path from "path"; -import util from "util"; import { getHardhatVersion } from "./packageInfo"; import { shouldUseProxy } from "./proxy"; @@ -26,9 +24,7 @@ export async function download( timeoutMillis = 10000, extraHeaders: { [name: string]: string } = {} ) { - const { pipeline } = await import("stream"); const { getGlobalDispatcher, ProxyAgent, request } = await import("undici"); - const streamPipeline = util.promisify(pipeline); let dispatcher: Dispatcher; if (process.env.http_proxy !== undefined && shouldUseProxy(url)) { @@ -52,10 +48,11 @@ export async function download( }); if (response.statusCode >= 200 && response.statusCode <= 299) { + const responseBody = await response.body.arrayBuffer(); const tmpFilePath = resolveTempFileName(filePath); await fsExtra.ensureDir(path.dirname(filePath)); - await streamPipeline(response.body, fs.createWriteStream(tmpFilePath)); + await fsExtra.writeFile(tmpFilePath, responseBody); return fsExtra.move(tmpFilePath, filePath, { overwrite: true }); } // undici's response bodies must always be consumed to prevent leaks From 68cf2a273f67fe1f3e75ef1faa193f779f2e3413 Mon Sep 17 00:00:00 2001 From: Franco Victorio Date: Tue, 27 Jun 2023 13:58:23 +0200 Subject: [PATCH 2/2] Create tricky-parents-warn.md --- .changeset/tricky-parents-warn.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/tricky-parents-warn.md diff --git a/.changeset/tricky-parents-warn.md b/.changeset/tricky-parents-warn.md new file mode 100644 index 0000000000..85c908f339 --- /dev/null +++ b/.changeset/tricky-parents-warn.md @@ -0,0 +1,5 @@ +--- +"hardhat": patch +--- + +Fixed an issue related to compiler downloads in node v18.16.x