From a3a0aa54681a7f8a21810f77d1afa678227dbe88 Mon Sep 17 00:00:00 2001 From: David Murdoch <187813+davidmurdoch@users.noreply.github.com> Date: Thu, 1 Jun 2023 15:50:12 -0400 Subject: [PATCH] fix: work around a Node v20 bug --- .../ethereum/src/forking/handlers/http-handler.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/packages/ethereum/ethereum/src/forking/handlers/http-handler.ts b/packages/ethereum/ethereum/src/forking/handlers/http-handler.ts index fb69a9f280..e57373e928 100644 --- a/packages/ethereum/ethereum/src/forking/handlers/http-handler.ts +++ b/packages/ethereum/ethereum/src/forking/handlers/http-handler.ts @@ -10,6 +10,21 @@ import { BaseHandler } from "./base-handler"; import { Handler } from "../types"; import Deferred from "../deferred"; +// Work around a node v20.0.0, v20.1.0, and v20.1.2 bug. The issue was fixed +// in v20.3.0. +// https://github.com/nodejs/node/issues/47822#issuecomment-1564708870 +// Safe to remove once support for Node v20 is dropped. +if ( + // webpack will replace process.env.IS_BROWSER with a boolean + !process.env.IS_BROWSER && + process.versions && + // check for `node` in case we want to use this in deno/bun/etc + process.versions.node && + process.versions.node.match(/20\.[0-2]\.0/) +) { + require("net").setDefaultAutoSelectFamily(false); +} + const { JSONRPC_PREFIX } = BaseHandler; export class HttpHandler extends BaseHandler implements Handler {