From 6c0d4a943fc55c34fd1e55a8b448e9d648331b9e 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 41b0fe5523..b8bd7fe7e3 100644 --- a/packages/ethereum/ethereum/src/forking/handlers/http-handler.ts +++ b/packages/ethereum/ethereum/src/forking/handlers/http-handler.ts @@ -9,6 +9,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 {