G
YouTube TikTok Games
Skip to content

fix(request): preserve runtime fetch proxy configuration - #162

Draft
mattsse wants to merge 1 commit into
mainfrom
mattsse/fix-runtime-env-proxy
Draft

mattsse wants to merge 1 commit into
mainfrom
mattsse/fix-runtime-env-proxy

Conversation

@mattsse

@mattsse mattsse commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

With NODE_USE_ENV_PROXY=1, loading the request transport can make Node 22 RPC/provider calls bypass the environment proxy. A key-free local reproduction succeeds with built-in fetch before importing current main's Undici 8.10.2, then fails with ENOTFOUND for an origin reachable only through the proxy.

Undici 8 initializes undici.globalDispatcher.2 with a plain Agent and replaces undici.globalDispatcher.1 with its compatibility wrapper. Node 22's built-in fetch uses the latter, so its existing EnvHttpProxyAgent is lost. This also affects viem's default HTTP transport.

Route the request transport's Undici imports through a small shim that captures the existing v1 dispatcher before initialization and restores it afterward. Explicit Undici request dispatchers and its v2 dispatcher remain independent. This preserves existing runtime proxy/custom-dispatcher configuration without changing the packaged Node version or TLS settings. The shim relies on Undici's shared dispatcher symbol; fresh-process tests cover that compatibility boundary.

Validation:

  • Full macOS arm64 Node 22.22.3 suite: 302 tests across 23 files. GitHub Linux x64 Node 22.23.3 CI also passes all 302 tests, code/types, changelog, dependency scan, and aggregate checks.
  • Six fresh-process regressions pass on Node 22.22.3 and Node 24.19.0: built-in fetch and viem through a local proxy, NO_PROXY bypass, proxy opt-in disabled, explicit Undici proxy use, and custom legacy dispatcher preservation. Disabling restoration reproduces the proxy and custom-dispatcher failures.
  • Repository code checks, source/test type checks, TypeScript build, and changelog validation pass.
  • pnpm package builds the request binary; --version smoke test passes. A loopback proxy harness loads the actual bundled CLI using PKG_EXECPATH=PKG_INVOKE_NODEJS: RPC fetch retains the original dispatcher and succeeds under both the SHA-256-verified v0.11.0 release's Node 22.22.3 runtime and the newly built Node 22.23.2 runtime.
  • Control: latest raw Undici import breaks proxy routing under the official Node 22.22.3 runtime; Node 24.19.0 retains routing.

Supplemental validation in the original cloud environment at exact PR commit 9cf4e0c8794af1202b67846bb77a019109dcaf44:

  • The bundled Node 22.22.3 runtime reaches the public RPC and returns chain ID 4217 before importing raw Undici 8.10.2, then fails with EAI_AGAIN after that import. Loading the fixed request module preserves the existing dispatcher and the public RPC again returns chain ID 4217.
  • Node 24 succeeds before and after import, and all six proxy regression tests pass on Node 24 in the original cloud environment.
  • The official Linux packaging script successfully builds tempo-request. An isolated empty-home dry-run against the public RPC returns chain ID 4217. A separate packaged fixed-module viem probe under Node 22.23.2 also returns chain ID 4217.
  • Source and test type checks pass. The full cloud suite has 283 passed and 19 failed, with failures caused by missing sqlite3 (spawn sqlite3 ENOENT and downstream session assertions); the cloud full suite is not green. The macOS and GitHub Linux CI suites above still pass all 302 tests.
  • Vitest workers are unsupported under the old bundled Node 22 runtime because of --require; direct packaged probes were used for that runtime.

The automated loopback proxy fixture uses HTTP and a reserved .invalid origin; the supplemental public RPC probes cover the original cloud network path. No credentials or payment operations were used, and existing runtime wrappers were not changed.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant