Skip to content

fix(ext/node): satisfy agent-base node:https stack-trace check - #34264

Merged
bartlomieju merged 1 commit into
mainfrom
fix/https-agent-base-stack-marker
May 20, 2026
Merged

bartlomieju merged 1 commit into
mainfrom
fix/https-agent-base-stack-marker

Conversation

@bartlomieju

Copy link
Copy Markdown
Member

npm install (and any other consumer of @npmcli/agent,
http-proxy-agent, or https-proxy-agent) has been failing under deno
with ERR_INVALID_PROTOCOL: Protocol "https:" not supported. Expected "http:", thrown synchronously from http.ClientRequest. The
polymorphic agent in those packages, which extends agent-base,
reports protocol: "http:" even for https.request(...).

The root cause is agent-base@7's protocol getter. When its own
setter hasn't run yet — the common case for the singleton agents
@npmcli/agent caches — it falls back to scanning the current stack
for (https.js: or node:https: to decide whether the caller is the
https module. Real node satisfies that by virtue of its script URL
(node:https:NNN:CC), but the deno polyfill's stack frames read
ext:deno_node/https.ts:NNN:CC, so neither pattern matched, the agent
assumed http, and http.ClientRequest saw options.protocol "https:" !== agent.protocol "http:" and threw.

Encode the marker in the request function's name so its call frame
reads at node:https:request (...) and agent-base's substring check
matches. The added unit test mirrors agent-base's protocol getter
exactly and asserts https.request(httpsUrl, { agent }) no longer
throws ERR_INVALID_PROTOCOL; with the marker removed the test fails
with the original error, so it's a real regression guard.

`agent-base` (used by `@npmcli/agent`, `http-proxy-agent`, etc.) figures
out whether a polymorphic agent should behave as https by scanning the
current stack for `(https.js:` or `node:https:`. Without a marker the
stack only contained our polyfill path (`ext:deno_node/https.ts`) and
the agent reported `protocol: "http:"`, causing `http.ClientRequest` to
throw `ERR_INVALID_PROTOCOL` against any `https:` URL. This broke
`npm install` (via `make-fetch-happen` -> `@npmcli/agent` ->
`agent-base`) and similar consumers.

Encode the marker in the `request` function's name so its stack frame
becomes `at node:https:request (...)`.
@bartlomieju
bartlomieju merged commit 99c6f7a into main May 20, 2026
136 checks passed
@bartlomieju
bartlomieju deleted the fix/https-agent-base-stack-marker branch May 20, 2026 12:18
littledivy pushed a commit to crowlKats/deno that referenced this pull request Jun 10, 2026
…and#34264)

`npm install` (and any other consumer of `@npmcli/agent`,
`http-proxy-agent`, or `https-proxy-agent`) has been failing under deno
with `ERR_INVALID_PROTOCOL: Protocol "https:" not supported. Expected
"http:"`, thrown synchronously from `http.ClientRequest`. The
polymorphic agent in those packages, which extends `agent-base`,
reports `protocol: "http:"` even for `https.request(...)`.

The root cause is `agent-base@7`'s `protocol` getter. When its own
setter hasn't run yet — the common case for the singleton agents
`@npmcli/agent` caches — it falls back to scanning the current stack
for `(https.js:` or `node:https:` to decide whether the caller is the
https module. Real node satisfies that by virtue of its script URL
(`node:https:NNN:CC`), but the deno polyfill's stack frames read
`ext:deno_node/https.ts:NNN:CC`, so neither pattern matched, the agent
assumed http, and `http.ClientRequest` saw `options.protocol "https:"
!== agent.protocol "http:"` and threw.

Encode the marker in the `request` function's name so its call frame
reads `at node:https:request (...)` and agent-base's substring check
matches. The added unit test mirrors agent-base's `protocol` getter
exactly and asserts `https.request(httpsUrl, { agent })` no longer
throws `ERR_INVALID_PROTOCOL`; with the marker removed the test fails
with the original error, so it's a real regression guard.
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